這裏是我的代碼:錯誤試圖通過ashx的處理程序來顯示圖像時 - 的圖片:「http://本地主機:57157/......」無法顯示,因爲它包含錯誤
HTML:<img src="thumbCreate.ashx?Id=223" alt="asd" />
HTTP處理:`
public void ProcessRequest (HttpContext context)
{
CreateThumbNail(context);
}
private void CreateThumbNail(HttpContext context)
{
string resourceId = context.Request.QueryString["Id"];
context.Response.Write("No resource found for Id = " + resourceId);
Bitmap original = new Bitmap("C:/Devp/My work/ASHXSampleApp/Images/Desert.jpg");
int oWidth = original.Width;
int oHeight = original.Height;
int preferredWidth = 80;
int preferredHeight = 100;
int thumbWidthFactor = oWidth/preferredWidth;
int thumbHeightFactor = oHeight/preferredHeight;
int maxFactor = Math.Max(thumbWidthFactor, thumbHeightFactor);
int thumbNailWidth = oWidth/maxFactor;
int thumbNailHeight = oHeight/maxFactor;
Bitmap thumbNailImage = (Bitmap)original.GetThumbnailImage(thumbNailWidth, thumbNailHeight, ThumbNailCallback, IntPtr.Zero);
context.Response.ContentType = "image/Jpeg";
thumbNailImage.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}`
但這代碼不顯示圖像。當我手動嘗試在Firefox中運行處理程序時,它給了我一個錯誤: - 「圖像」http:// localhost:57157/ASHXSampleApp/thumbCreate.ashx?Id = 223「無法顯示,因爲它包含錯誤。任何想法?
請調試您的代碼並更新有關您找到的異常/消息/值的信息的問題。 –
當我調試處理程序代碼時沒有例外。但我不能看到在HTML頁面呈現的圖像。當我嘗試在Firefox中運行頁面時,我可以在控制檯中看到錯誤 - '圖像損壞或被截斷:http:// localhost:57157/ASHXSampleApp/thumbCreate.ashx?Id = 223'。當我手動嘗試運行處理程序時,出現錯誤 - 「圖像」http:// localhost:57157/ASHXSampleApp/thumbCreate.ashx?Id = 223「無法顯示,因爲它包含錯誤。 – GirishK
我沒有在web.config中進行任何設置。我需要在web.Config中進行任何設置嗎? – GirishK