Problem with Dynamic Images in WebConrols

A

Ali Khawaja

I have trying to build a control: PieChartControl : System.Web.UI.WebControls.WebContro
in which i am creating a dynamic image based on some data from database

in the render method of the control, I set the content type of image/jpeg
this.Context.Response.ContentType = "image/jpeg"
and then once I am done with creating the image, I save it to the output stream
bmp.Save(this.Context.Response.OutputStream, ImageFormat.Jpeg)

I added it to the toolbar, and dropped on my test form, and its shows characters like its not recognizing the content type

Can anyone please let me know what I am doing wrong

I'll really appreciate any help
Thank
Al
 
M

Mark Fitzpatrick

You need to call this control from a page that has no content. Basically
it's empty, no HTML or anything (even one space sent to the browser can mess
this up). You then call this page as the source of an image tag. For example
<img src="myimage.aspx"> where myimage.aspx has the control in it. You can't
embed the binary data into the web page which is why you get the dump of
characters.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage


Ali Khawaja said:
I have trying to build a control: PieChartControl : System.Web.UI.WebControls.WebControl
in which i am creating a dynamic image based on some data from database.

in the render method of the control, I set the content type of image/jpeg:
this.Context.Response.ContentType = "image/jpeg";
and then once I am done with creating the image, I save it to the output stream:
bmp.Save(this.Context.Response.OutputStream, ImageFormat.Jpeg);

I added it to the toolbar, and dropped on my test form, and its shows
characters like its not recognizing the content type.
 
J

Jeffrey Tan[MSFT]

Hi Ali,

Does Mark's reply makes sense to you? Do you still have any concern?

Please feel free to let me know, I will help you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top