生产计算器的图像我有我的居住web应用程序的,我要为给用户的上下文之外图像的目录。目前,我正在使用IHttpHandler来为图像提供服务,并使用一些JavaScript来浏览一组图像(现在导航是原始的)。我遵循使用IHttpHandler为图像提供服务的示例,但是当我在Firefox中查看图像时,浏览器挂起,当我在IE中查看时,出现“堆栈溢出在线:0”。的IHttpHandler在IE
规范了IHttpHandler
Public Class ShowImage : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) _
Implements IHttpHandler.ProcessRequest
Dim picid As String
If context.Request.QueryString("id") IsNot Nothing Then
picid = context.Request.QueryString("id")
Else
Throw New ArgumentException("No parameter specified")
End If
'' Convert Byte[] to Bitmap
context.Response.Cache.SetCacheability(HttpCacheability.NoCache)
context.Response.Cache.SetNoStore()
context.Response.Cache.SetExpires(DateTime.MinValue)
Dim newBmp As Bitmap = GetPhoto(picid)
If newBmp IsNot Nothing Then
Dim imgGraphics As Graphics = Graphics.FromImage(newBmp)
imgGraphics.DrawImageUnscaled(newBmp, 0, 0, 640, 480)
context.Response.StatusCode = 200
context.Response.ContentType = "image/jpeg"
newBmp.Save(context.Response.OutputStream, ImageFormat.Jpeg)
newBmp.Dispose()
Else
'' Return 404
context.Response.StatusCode = 404
context.Response.End()
End If
End Sub
...
Public ReadOnly Property IsReusable() As Boolean _
Implements IHttpHandler.IsReusable
Get
Return True
End Get
End Property
End Class
下面是调用了IHttpHandler的上述定义的javascript代码:
function updateImage(){
var ddlPhotos = document.getElementById("ddlPhotos");
var selected = ddlPhotos.options[ddlPhotos.selectedIndex].value;
if(selected != -1){
// Update the image
retrievePicture(document.getElementById("propertyImage"), selected)
}
}
function retrievePicture(imgCtrl, picid)
{
imgCtrl.src = 'ShowImage.ashx?id=' + picid;
}
最后,这里的img标签即是 “占位符”:
<img src="#"
alt="Property Photo"
width="640px"
height="480px"
id="propertyImage"
onload="retrievePicture(this, '<%= pictureId.value %>');"
/>
我很困惑,为什么的JavaScript似乎失控...
谢谢你,谢谢你。我把onload事件移动到了页面主体(这对我来说很好),并且FF工作正常,堆栈溢出在IE中消失了。 – toddk 2009-06-24 14:22:53