A generic error occurred in GDI+.

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

hi

asp.net 2.0

I'm experimenting with GDI+ in asp.net and get an "A generic error occurred
in GDI+." exception.

Below is my code, I've marked a line with "<<<<-- here". It's here the
exception is thrown.

(test.FileBytes - FileBytes is an array of bytes) test is an enity class,
and I'm storing the images in the database. When tested the image which
test.FileBytes is based on is a GIF

MemoryStream ms = new MemoryStream(test.FileBytes);
System.Drawing.Image image = System.Drawing.Image.FromStream(ms);
Bitmap img = new Bitmap(new Bitmap(image));
Font font = new Font("Verdana", 12);
Graphics gfx = Graphics.FromImage(img);
gfx.DrawString("Hello World", font, Brushes.CadetBlue, 50, 50);
img.Save(ms, ImageFormat.Bmp); <<<<-- here
ms.WriteTo(Response.OutputStream);

any suggestions?
 
its unclear what you are trying to do, but you error is probably you
usage of the memory stream. you create a non-resizeable memory stream,
and read to the end. then you try to write to it without a seek to the
start, so there is nowhere to write (you also do no check that it would
fit anyway). also the bitmap class recommends not using the same stream
for reading and writing.

-- bruce (sqlwork.com)
 
Back
Top