Dynamically generated png images

  • Thread starter Thread starter Chris Jones
  • Start date Start date
C

Chris Jones

I am creating a web page that dynamically generates an
image, which is placed in an Image control. Everything
works fine for .gif and .jpeg files. I would prefer
using .png format, but that doesn't seem to work.

Here's how it's setup.

The Image control has URL property "image.aspx".

The Page_Load method of image.aspx contains the code

{
//generate image
Bitmap bitmap = ...
//Return the image
Response.ContentType = "image/png";
bitmap.Save(Response.OutputStream,ImageFormat.Png);
}

If ContentType is "image/jpeg" and bitmap.Save's 2nd
parameter is ImageFormat.Jpeg, everything works fine.
Same for ContentType = "image/gif" and bitmap.Save's 2nd
argument is ImageFormat.Gif. When the code appears as
above, the Image control displays the dreaded "X" icon
indicating that the image can't be found.

Note that I can use a different version of the Save
method for the bitmap to write the .png image to a file.
I can then open the file successfully in IE.

I am using VS.NET 2002 and .NET framework 1.0.

Thanks for your help.

Chris Jones
LogexSoft
(e-mail address removed)
 
Unless the browser you're working with supports PNG files, this is pretty
much what you should expect.

HTH,

Kevin Spencer
Microsoft FrontPage MVP
Internet Developer
http://www.takempis.com
Big things are made up of
lots of Little things.
 
Back
Top