You know you’re doing good when your application crashes with an exception as detailed as “a generic error occurred in gdi+”. That is about as, well generic, as it gets :- )
In my particular case I was constructing an Image down in my DAO using the FromStream method, like so:
Image result; using (FileStream file = File.OpenRead(filename)) { result = Image.FromStream(file); file.Close(); } return result;
I was doing this so that I could know for a fact that the file was being disposed of properly. I didn’t want to have any orphaned file references locking up the file in case I later needed to delete it.
The problem was that up in my UI I was attempting to call the Save method on Image to dump its contents out to the ASP.NET response stream, like so:
img.Save(HttpContext.Response.OutputStream, ImageFormat.Jpeg);