2012-03-27 67 views
-1

我使用自己的用于图像处理的类,如载荷,缩略图,....图像裁剪与GDI呈现+

一般来说,这种代码创建图像对象;

Bitmap result = new Bitmap(width, height, PixelFormat.Format32bppArgb); 

和此代码发布到response对象显示在浏览器中。

HttpContext.Current.Response.AddHeader("ContentType", "image/png"); 
     using (MemoryStream memStream = new MemoryStream()) 
     { 
      memStream.Seek(0, SeekOrigin.Begin); 
      Result.Save(memStream, ImageFormat.Png); 
      memStream.WriteTo(HttpContext.Current.Response.OutputStream); 
     } 
     Result.Dispose(); 

在某些情况下,浏览器显示正确的图像,但有时会显示像这样的裁剪图像。

enter image description here

这是图像打破与我的代码或相关的浏览器?

回答

1

如果图像格式为PNG,则需要使用中间MemoryStream(因为PNG需要保存可查找的流)。尝试使用jpg文件来查看您的代码是否正常工作。

检查ASP.NET [Image Handler]