how to create a gif or png dynamicaly in .aspx and return in response?

G

Guest

how to create a gif or png dynamicaly in .aspx and return in response?
Hi Daniel,

You can create a graphics from bmp on the fly and after modifying the
graphics obtained you can render it to Response.OutputStream.

This stream will be directly served to requesting browser. You can also
display this image on any HTML using standard <img> tag. Provide the web
accessible path of this image rendering page in src elemnet of the <img> tag
and your image will be shown with the HTML output by browser.

Sample code snippet:
<CODE>
Bitmap bmp = new Bitmap(200, 100);
Graphics gr = Graphics.FromImage(bmp);
gr.Clear(Color.WhiteSmoke);
gr.DrawString("Test String", new Font("Arial", 12), Brushes.Blue, 10, 10);
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
gr.Dispose();
bmp.Dispose();
Response.End();
</CODE>
 
G

Guest

Rahul Anand said:
Hi Daniel,

You can create a graphics from bmp on the fly and after modifying the
graphics obtained you can render it to Response.OutputStream.

This stream will be directly served to requesting browser. You can also
display this image on any HTML using standard <img> tag. Provide the web
accessible path of this image rendering page in src elemnet of the <img> tag
and your image will be shown with the HTML output by browser.

Sample code snippet:
<CODE>
Bitmap bmp = new Bitmap(200, 100);
Graphics gr = Graphics.FromImage(bmp);
gr.Clear(Color.WhiteSmoke);
gr.DrawString("Test String", new Font("Arial", 12), Brushes.Blue, 10, 10);
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
gr.Dispose();
bmp.Dispose();
Response.End();
</CODE>

Just to add, you can find a little more explanation here:

http://www.codeproject.com/aspnet/aspnet_web_graphics.asp
 

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