0

I'm simply trying to write a bitmap to the Response.OutputStream. Here's what i have:

System.Drawing.Bitmap outputImage = 
    System.Drawing.Image.FromHbitmap(psd.GetHBitmap());            
Response.Clear();
Response.ContentType = "image/bmp";
Response.Flush();

// error occurs here
outputImage.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Bmp);

outputImage.Dispose();
Response.End();

Anyone know what the problem might be?

Steven
  • 17,851
  • 66
  • 182
  • 285

2 Answers2

0

From the System.Drawing Namespace documentation on MSDN:

Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions. For a supported alternative, see Windows Imaging Components.

You seem to be hitting on one of the reasons why it isn't supported.

Here is a detailed article explaining the ins and outs of the issues.

There are alternatives mentioned in this question, apart from Windows Imaging Components mentioned in the warning on MSDN.

Community
  • 1
  • 1
Oded
  • 477,625
  • 97
  • 867
  • 998
0

Many of the GDI errors that I have encountered from the ASP.NET environment deal with folder / file permissions problems, which may not apply here. Does the worker process have read access to the original file? Are you writing a temp file to a folder which the WP does not have access to?

feathj
  • 2,909
  • 2
  • 21
  • 22