Dynamically generated png images

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)
 
K

Kevin Spencer

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.
 

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