Output Dynamic Graphic from Webcontrol

J

Jonathan Wood

I've figured out how to create an image on the fly on my Website. Once
created, I write the image to the page using code like this:

Bitmap bm = [...]
[...]
Response.ContentType = "image/jpeg";
bm.Save(Response.OutputStream, ImageFormat.Jpeg);

The code I have does indeed display the graphic, but the page shows nothing
else. I need to write the image to a location within my Web page.

My preference would be to create a Web control, that I can embed in the
page, and then write the image from the control. However, the control's
Render handler provides an HtmlTextWriter argument, which does not have an
OutputStream property.

How can I output the graphic as the control's output?

Thanks.

Jonathan
 
N

nick chan

your control needs to output an Image location as a string
then, another page will actually load the image
u can either create another aspx page, or read up about ashx/axd
 
M

marss

How can I output the graphic as the control's output?

1. Add new Generic Handler to the project. Name it, for example,
"Handler1".

2. Put the code for image creation inside of ProcessRequest method.
void ProcessRequest(HttpContext context)
{
//create image
Bitmap bm = [...]
[...]
context.Response.ContentType = "image/jpeg";
bm.Save(context.Response.OutputStream, ImageFormat.Jpeg);
}

3.Use it as an ordinary image url
<asp:Image ImageUrl="~/Handler1.ashx" ...

Regards,
Mykola
http://marss.co.ua - Casual ideas for web development
 
J

Jonathan Wood

Wow. New stuff for me. Will take me a while to figure it all out but looks
interesting. Thanks!

Jonathan

marss said:
How can I output the graphic as the control's output?

1. Add new Generic Handler to the project. Name it, for example,
"Handler1".

2. Put the code for image creation inside of ProcessRequest method.
void ProcessRequest(HttpContext context)
{
//create image
Bitmap bm = [...]
[...]
context.Response.ContentType = "image/jpeg";
bm.Save(context.Response.OutputStream, ImageFormat.Jpeg);
}

3.Use it as an ordinary image url
<asp:Image ImageUrl="~/Handler1.ashx" ...

Regards,
Mykola
http://marss.co.ua - Casual ideas for web development
 
M

Munna

Wow. New stuff for me. Will take me a while to figure it all out but looks
interesting. Thanks!

Jonathan


1. Add new Generic Handler to the project. Name it, for example,
"Handler1".
2. Put the code for image creation inside of ProcessRequest method.
void ProcessRequest(HttpContext context)
{
//create image
Bitmap bm = [...]
[...]
context.Response.ContentType = "image/jpeg";
bm.Save(context.Response.OutputStream, ImageFormat.Jpeg);
}
3.Use it as an ordinary image url
<asp:Image ImageUrl="~/Handler1.ashx" ...
Regards,
Mykola
http://marss.co.ua- Casual ideas for web development

Hi

here is few links about dynamic image display that will help you kick
start

http://www.sitepoint.com/article/generating-asp-net-images-fly
http://aspalliance.com/articleViewer.aspx?aId=141&pId=

Best of luck
Munna
www.munna.shatkotha.com
www.munna.shatkotha.com/blog
www.shatkotha.com
 

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

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top