Output Dynamic Graphic from Webcontrol

  • Thread starter Thread starter Jonathan Wood
  • Start date Start date
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
 
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
 
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
 
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
 
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
 
Back
Top