Last post Jun 24, 2009 03:21 PM by IranianCuriousBoy
Jun 24, 2009 02:10 AM|IranianCuriousBoy|LINK
I create a Bitmap and when try to save it in png format there is an error. It says:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
There is no problem saving in gif or jpeg formats.
and my code:
// Create a new Bitmap object, 50 x 50 pixels in size
Image canvas = new Bitmap(50, 50);
// create an object that will do the drawing operations
Graphics artist = Graphics.FromImage(canvas);
// draw a few shapes on the canvas picture
artist.FillEllipse(Brushes.Red, 3, 30, 30, 30);
artist.DrawBezier(new Pen(Color.Blue, 3), 0, 0, 40, 15, 10, 35, 50, 50);
// return the picture
// now the drawing is done, we can discard the artist object
// also the Bitmap
Jun 24, 2009 03:44 AM|Ambran|LINK
The solution is to use a Response.BinaryWrite like this:
MemoryStream io = new MemoryStream();
Response.BinaryWrite( io.GetBuffer() );
Jun 24, 2009 03:21 PM|IranianCuriousBoy|LINK
Reason:The PNG implementation in System.Drawing requires the use of a searchable stream, which