Dear Craig,
I've an Windows Form custom control (an analog gauge control) to which I want to add the functionality of returning the drawn gauge image as bytes. I wanted to create a Bitmap image from the Graphics object. Unfortunately, I learnt that the Bitmap() constructor that took in a Graphics object doesn't actually create a representation of the image drawn on the Graphics object. And I am stuck.
I want to know a couple of things:
1.
I have a fully drawn image on a Graphics object. I want to save this into a Bitmap object. I don't have the liberty of creating a new Graphics object (the Graphics property of PaintEventArgs is read-only) and that might rule out the Graphics.FromImage(bitmap) approach.
2.
Also, I want to use this control on my ASP.Net code-behind class for generating an image of itself that would be streamed to the browser.
Say, I would add a method, GetImageAsBytes(), that would return a byte array of the image of the control.
I would write this image using
Response.ContentType = "image/gif";
Response.BinaryWrite(objGauge.GetImageAsBytes());
Response.End();
Would this approach work? What's the Pros & Cons of using a Windows Forms control on an ASP page? Would I be able to get a Graphic context at all (the code sure didn't throw up any errors).
Ideas?
Regards,
Vyas