Including HTML When Outputing a Dynamically Drawn PNG

P

premier

I have a web page that's taking in data from text boxes, drawing a
chart to represent the data, and then outputting the chart in PNG
format. What I cant figure out how to do, is to output the chart as
part of an aspx web page.

Ideally, I'd output it to the bottom of the web page that the user
used to send the data to the server. Or, I could output the PNG as
part of a new Web page. I'm just lost on the details.

I'm currently outputting the PNG as follows (the memorystream is
needed when dealing with PNGs):

Dim myMemoryStream As New MemoryStream()
myBitmap.Save(myMemoryStream, ImageFormat.Png)
myMemoryStream.WriteTo(Response.OutputStream)
myMemoryStream.Close()

Since I have the memory stream, perhaps I could insert into a file ?
Any guidance is appreciated.

Thanks
 
T

Teemu Keiski

Hi,

you need to return it as part of separate request since you cannot mix HTML
with other content such as images.. E.g on your aspx page you'd have IMG tag
whose src attribute points to the URL which returns the image. In that case,
the URL can point to a static file on the server, or aspx page serving it
from memory as your code below does.
 
H

hi

Hi,

you need to return it as part of separate request since you cannot mix HTML
with other content such as images.. E.g on your aspx page you'd have IMG tag
whose src attribute points to the URL which returns the image. In that case,
the URL can point to a static file on the server, or aspx page serving it
from memory as your code below does.

Thanks for replying.

Okay, so I want the page that's returned (I'll call it WebForm2.aspx)
to look like the original page (WebForm1.aspx), except that
WebForm2.aspx will include at the bottom of the page an image tag that
points to the image I just generated.

What I dont understand is: how do I make an the ImageURL attribute in
Image tag in the WebForm2.aspx page point to a memorystream.

I cant beleive that I got GDI+ working (this is the first time I've
ever used it) and I cant figure out this simple HTML display issue!

Thanks for you help



If I'm understanding correctly, I would use
 
T

Teemu Keiski

Not sure if you understood,

you have a page which works only with the image generating, let's call it
"generateimage.aspx". It has that code

....
Dim myMemoryStream As New MemoryStream()
myBitmap.Save(myMemoryStream, ImageFormat.Png)
myMemoryStream.WriteTo(Response.OutputStream)
myMemoryStream.Close()
....
and it does not return any HTML, (clear the HTML part from aspx except the
@page directive)

Then you have the another page be it "WebForm1.aspx", which has the image
tag pointing to this page

....
<img src="generateimage.aspx" border="0">
....

e.g you have the img tag on page which shows the image, and it passes
requesting for the image resource to generateimage.aspx page (you can pass
parameter etc in querystring to generateimage.aspx).

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
 

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,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top