When my images are being loaded from my database on my web server, I see the following error:
A generic error occurred in GDI+. at System.Drawing
Probably for the same reason that this guy was having problems - because the for a lifetime of an Image constructed from a Stream
, the stream must not be destroyed.
So if your GetImage
function constructs the returned image from a stream (e.g. a MemoryStream
) and then closes the stream before returning the image then the above will fail. My guess is that your GetImage
looks a tad like this:
Image GetImage(int id)
{
byte[] data = // Get data from database
using (MemoryStream stream = new MemoryStream(data))
{
return Image.FromStream(data);
}
}
If this is the case then try having GetImage
return the MemoryStream
(or possibly the byte array) directrly so that you can create the Image
instance in your ProcessRequest
method and dispose of the stream only when the processing of that image has completed.
This is mentioned in the documentation but its kind of in the small print.