A generic error occurred in GDI+.


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?
 
Ad

Advertisements

B

bruce barker

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top