This is a simple article to demonstrate rendering a graphic image on the fly from within a server control without using an .aspx page. One caveat, I have not gotten this method to work at design time, only run time.
On an .aspx page, you would normally create a bitmap with GDI+, and then use this syntax to draw it:
Response.ContentType = "image/jpeg";
The only examples I had seen which created graphics on the fly (buttons and charts) all included an .aspx page which they would call from the
Render method with a query string. The .aspx page would then render the graphic based on the query string.
Here is a way to render the graphic at runtime without the .aspx page.
protected override void Render(HtmlTextWriter output)
Bitmap objBitmap = new Bitmap(120,30);
Graphics objGraphics = Graphics.FromImage(objBitmap);
objGraphics.DrawString("Submit", new Font("Tahoma",8),
new SolidBrush(Color.Green), 16,8);
Page.Response.ContentType = "image/jpeg";
I am not sure of the implications of writing directly to the
Page class from within the
Render method, but this works at runtime. If anyone knows of a method that works at design time, please let me know.