all groups > dotnet drawing api > december 2003 >
You're in the

dotnet drawing api

group:

GDI+ in a ASP.NET custom control


GDI+ in a ASP.NET custom control Gerben van Loon
12/29/2003 8:30:35 PM
dotnet drawing api:
Hi,

Hope someone can help me on this. I like to make an own ASP.NET charting
control, so I need to render some graphics in a custom made control. I
already found this example:

protected override void Render(HtmlTextWriter output)
{
Bitmap objBitmap = new Bitmap(200,200);
Graphics objGraphics = Graphics.FromImage(objBitmap);
//draw some shapes
Page.Response.Clear();
Page.Response.ContentType = "image/jpeg";
objBitmap.Save(Page.Response.OutputStream, ImageFormat.Jpeg);
}

But the problem with this is that the graphics drawn are not visible at
design time in Visual Studio. And the Page.Response.Clear() removes all
other controls on the page where I'm using the self made control.

Some other solution I thought about is inheriting my control from the
"System.Web.UI.WebControls.Image" control. In that control I could do the
following:

Bitmap bmp = new Bitmap(200,200);
Graphics g = Graphics.FromImage(bmp);
//draw some shapes
bmp.Save(Page.Server.MapPath("temp.png"),ImageFormat.Png);
this.ImageUrl = "temp.png"; //Set the imageUrl property of the image control

I this way the graphics are directly shown in Visual Studio. But the problem
is that you have to temporarily write away a file to the hard disk, so also
this solution isn't ideal.
Someone knows how I can solve one of my solutions, or maybe got another
solution for my problem?

Cheers,

Gerben.

Re: GDI+ in a ASP.NET custom control Gerben van Loon
1/4/2004 11:06:36 PM
Hi there,

Already solved my problem. The solution (just in case somebody else is
having the same problem):

Using dynamic graphics in a control without the use of temp files on your HD
is posible through HTTP Handlers. More information can be found in the book:
"Developing Microsoft ASP.NET Server Controls and Components" from Microsoft
Press.

Cheers,

Gerben.

[quoted text, click to view]

AddThis Social Bookmark Button