Rendering graphics on a custom control

G

Gerben van Loon

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 which sends back a bitmap from the control to the
page:

Page.Response.Clear();
Page.Response.ContentType = "image/jpeg";
myBitmap.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:

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.
 
J

Jos

Gerben said:
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 which sends back a bitmap from
the control to the page:

Page.Response.Clear();
Page.Response.ContentType = "image/jpeg";
myBitmap.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:

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.

Use a separate aspx file to generate the image.

Then, redesign your control so that it's just a container for an
HtmlImage or an Image control. Make the "src" or the "ImageUrl"
properties respectively point to your aspx file.

Use URL parameters (QueryString) to set the parameters of your
charts.

e.g.
Image1.src="mychart.aspx?position=10,color=red"
(probably, the parameters will be dynamic off course)
 
G

Gerben van Loon

Hi,

First of all thanks for your reply Jos. Great, I'm going to try that
solution you suggested. Only 1 more question, am I still having design time
support (preview the drawn graphics) in Visual Studio with your solution?

Thanks for the help so far!

Cheers,

Gerben.
 
J

Jos

Gerben said:
Hi,

First of all thanks for your reply Jos. Great, I'm going to try that
solution you suggested. Only 1 more question, am I still having
design time support (preview the drawn graphics) in Visual Studio
with your solution?

No.
Sorry, I didn't read your first message very carefully.
 
G

Gerben van Loon

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top