-1

I am using my own class for image processing , like load , thumbnail , ....

In general , this code create images object;

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

and this code post it to response object to show in browser.

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();

In some cases , the browser(s) show the correct image but sometimes show the cropped image like this.

enter image description here

Is this image breaking related to my code or related to browsers ?

Mironline
  • 2,755
  • 7
  • 35
  • 61

1 Answers1

1

If the image format is PNG, you need to use an intermediate MemoryStream (because PNGs require a seekable stream to be saved). Try using jpg file to see that your code is working.

Check ASP.NET [Image Handler]

Community
  • 1
  • 1
volody
  • 6,946
  • 3
  • 42
  • 54