我創建了使用ASHX處理程序從文件系統檢索圖像的代碼。該代碼正確顯示圖像在Chrome,但我在IE中得到一個破碎的形象:ASHX圖像處理程序使用chrome而不是IE8
public class ImageHandler : IHttpHandler
{
private int? QS_ImageID
{
get
{
int? temp = null;
if (HttpContext.Current.Request.QueryString["ImageID"] != null)
temp = HA.Utility.DataHelper.ParseDbInt(HttpContext.Current.Request.QueryString["ImageID"]);
return temp;
}
}
private bool QS_Thumbnail
{
get
{
bool thumbNail = false;
if (HttpContext.Current.Request.QueryString["Thumbnail"] != null)
{
if (HttpContext.Current.Request.QueryString["Thumbnail"].Equals("1"))
thumbNail = true;
}
return thumbNail;
}
}
public void ProcessRequest(HttpContext context)
{
if (QS_ImageID.HasValue)
{
int uploadID = QS_ImageID.Value;
context.Response.ClearHeaders();
context.Response.ClearContent();
context.Response.Cache.SetNoStore();
context.Response.ContentType = UploadDAL.GetMetaData(uploadID).UploadContentType;
context.Response.AddHeader("Content-Disposition", "inline;");
if (QS_Thumbnail)
{
byte[] myImage = UploadDAL.GetFileThumbNail(uploadID);
context.Response.AddHeader("Content-Length", myImage.GetLength(0).ToString());
context.Response.BinaryWrite(myImage);
context.Response.End();
}
else
{
byte[] myImage = UploadDAL.GetFile(uploadID);
context.Response.AddHeader("Content-Length", myImage.GetLength(0).ToString());
context.Response.BinaryWrite(myImage);
context.Response.End();
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
您是否考慮過使用[庫來處理縮略圖生成](http://imageresizing.net)?如果你正在做自己的處理程序,[如果沒有,請檢查列表](http://nathanaeljones.com/163/20-image-resizing-pitfalls/)以避免。 – 2011-06-22 23:38:31
我暫時沒有積極開發該代碼,但我認爲使用庫(如您所建議的)是一種可行的方式。謝謝! – Kevin 2011-06-24 15:15:38