A general error occurred in gdi +. saving the image
Dear expert. I am getting an error while saving the image.
ClsImageManager objImgManager = new ClsImageManager();
Bitmap ImageBitmap = objImgManager.GetBitmapFromBytes(ImageData);
Response.ContentType = "image/tiff";
ImageBitmap.Save(Response.OutputStream, ImageFormat.Tiff);
ImageBitmap.Dispose();
Response.End();
when I used Image.format.jpeg the code works well, but when I change it to ImageFormat.Tiff then I get a generic error in gdi +.
source to share
It should be noted that the GDI / GDI + ( System.Drawing
) namespace is not officially supported in ASP.NET - see "Caution" at http://msdn.microsoft.com/en-us/library/system.drawing.aspx .
WIC is supposed to be used instead of GDI + (see http://weblogs.asp.net/bleroy/archive/2009/12/10/resizing-images-from-the-server-using-wpf-wic-instead- of-gdi.aspx )
It is said that many have successfully used GDI + in ASP.NET. You should most likely try to save the image to a memory stream (or file) and then write the saved image back. See this link for more details: http://www.west-wind.com/weblog/posts/2006/Oct/19/Common-Problems-with-rendering-Bitmaps-into-ASPNET-OutputStream
Other work might be associated with a user account. Apparently GDI / GDI + is bound to the device context (screen, printer, etc.) and they may not be available in service accounts. So you can try to run your ASP.NET code on some normal user account if it helps or not.
source to share
You may have to try to explicitly encode the image saving.
Check out the sample code at the bottom of this MSDN documentation on Image.Save
Image.Save Method (String, ImageCodecInfo, EncoderParameters)
The same steps can be applied to your save.
However, it could also be that your objImgManager is deleting the buffer where the image is stored before you can save it.
Bitmap ImageBitmap = objImgManager.GetBitmapFromBytes(ImageData);
You can work around this by making a copy of the image by doing the following:
Bitmap ImageBitmap = new Bitmap(objImgManager.GetBitmapFromBytes(ImageData));
source to share