|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThis 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";
objBitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.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 Here is a way to render the graphic at runtime without the .aspx page. using System.Drawing;
using System.Drawing.Imaging;
//...
protected override void Render(HtmlTextWriter output)
{
Bitmap objBitmap = new Bitmap(120,30);
Graphics objGraphics = Graphics.FromImage(objBitmap);
//Fill the background
objGraphics.FillRectangle(new SolidBrush(Color.LightBlue),0,0,120,30);
//Create blue-yellow bullet point
objGraphics.FillEllipse(new SolidBrush(Color.Blue),3,9,10,10);
objGraphics.FillEllipse(new SolidBrush(Color.Yellow),4,10,8,8);
//Draw text next to bullet point
objGraphics.DrawString("Submit", new Font("Tahoma",8),
new SolidBrush(Color.Green), 16,8);
//Render
Page.Response.Clear();
Page.Response.ContentType = "image/jpeg";
objBitmap.Save(Page.Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg);
//Tidy up
objGraphics.Dispose();
objBitmap.Dispose();
}
I am not sure of the implications of writing directly to the
|
||||||||||||||||||||||