Last post Apr 22, 2011 01:58 PM by grundebar
Apr 05, 2011 04:43 PM|grundebar|LINK
I am bored and looking into creating my own charting control mainly for the experience in GDI and databinding. I have the rudimentary basics complete that allow me to create an image based on some input parameters. I will eventually get to the databinding
portion, but the question I have now is, how to get the rendered image to the client. I currently see two options. 1) Save the image to the Response.OutputStream and set the appropriate response headers so that the binary data renders as an image on the client
side, or 2) save the rendered image on the server with a unique identifier and then link to that saved image. I am currently using option #1 and this works, but this means that you always have to point to your handler/custom page/etc. indirectly instead of
dropping a control on the page. How does the Microsoft Chart Control that started shipping with the 3.5 framework do it? Is there another option that I have overlooked for getting the rendered image to the client?
Apr 22, 2011 11:35 AM|grundebar|LINK
I thought I would simplify my question so that it might not be so intimidating and hopefully get a reply:
I have a server side Graphics object (a bitmap). How do I display that image on the client without having to save the image on the server or having to do something like this:
<img src="myFakeImage.aspx?param1=blah" />
Where myFakeImage.aspx sends the image to the response stream in binary format. Is there a third option?
Apr 22, 2011 01:58 PM|grundebar|LINK
Well, not to be defeated, I found a useful
CodeProject article that shows how to do something similar to what I wanted. It isn't 100% plug and play,but it gets me 95% of the way. Basically, I changed my chart class to inherit from the WebControls.Image class. I overrode the OnPreRender method to
point my ImageUrl property to a fake file with a custom extension (.img). I then created a handler for the img file type that then pulls information out of the context cache to render my chart to the output stream.
The end result: a control I can register that puts an image on the page without any intermediaries between my page and the class (besides the handler).