how to render a graphic and other objects in the same page?

A

André

Hi,

I try to create and render a graphic among other objects like e.g. tables,
labels, buttons.
The tables are not a problem, neither the graphic.

My problem is that i can't render both together. With the code below, i only
see the graphic, nothing else (no table, label, button).

How can i see the table and below the table, the graphic?
Thanks
André



My code:
Dim objBitmap As New Bitmap(400,200)
Dim objGraphic as Graphics = Graphics.FromImage(objBitmap)
Dim redBrush As New SolidBrush(Color.Red)
Dim blueBrush As New SolidBrush(Color.Blue)
Dim greenBrush As New SolidBrush(Color.Green)
Dim whiteBrush As New SolidBrush(Color.White)
Dim blackPen As New Pen(Color.Black, 2)
Dim sngheight(10) As Single
Dim sngValue(10) As Single
Dim max, x As Integer

.....

c = New TableCell
c.Text() = "this is a tablecell"
r.Cells.Add(c) 'add to row
t.Rows.Add(r) 'add to table
frm.Controls.Add(t) 'add to form
lit = New LiteralControl("<br>")
frm.Controls.Add(lit)

objGraphic.FillRectangle(whiteBrush, 0, 0, 400, 200)
objGraphic.DrawString("A525G", New Font("Arial", 10), New
SolidBrush(Color.White), 35, 8)

objGraphic.DrawLine(blackPen, New Point(0, 195), New Point(350, 195))
objGraphic.DrawLine(blackPen, New Point(5, 5), New Point(5, 200))
....

For i = 1 To 10
sngHeight(i) = (sngValue(i) / 50+i) * 190
objGraphic.FillRectangle(redBrush, 10 + x, 194 - sngHeight(i), 20,
sngHeight(i))
Next

Response.ContentType = "image/gif"
objBitmap.Save(Response.OutputStream, Drawing.Imaging.ImageFormat.Gif)
 
S

Steve C. Orr [MCSD, MVP, CSM, ASP Insider]

You need at least two pages to accomplish your goal. One to output the
image and one to output the rest of the page (including a link to the
image).

So put your image generation code in a file called "MyImage.aspx"
Now from your original page add an image tag that refers to that new image
page:
<img src="MyImage.aspx"/>

Here's more info:
http://SteveOrr.net/articles/ImproveYourImages.aspx
 
A

André

Thanks, i'll try

Steve C. Orr said:
You need at least two pages to accomplish your goal. One to output the
image and one to output the rest of the page (including a link to the
image).

So put your image generation code in a file called "MyImage.aspx"
Now from your original page add an image tag that refers to that new image
page:
<img src="MyImage.aspx"/>

Here's more info:
http://SteveOrr.net/articles/ImproveYourImages.aspx

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net
 
A

André

Hi Steve, here am i back ...
I did what you told me and it works.

But i have another strange problem. The graphic generated in the second file
(graf2.aspx) must receive values from the the first file. I do that with
cookies. It works when i send ONE cookie, but if i send two cookies from the
first file, i get the browser-error: "can't render the page (or something
like that) ... check your configuration etc ...".

Maybe a conflict between the 'Response'?
Can you see the problem and maybe solve it?
Thanks


I show you my code:
first file:
-------
Dim cok1 As New HttpCookie("cok1")
Dim cok2 As New HttpCookie("cok2")
cok1.Value = 150
Response.Cookies.Add(cok1)
cok2.Value = 50
Response.Cookies.Add(cok2)
.....
lit = New LiteralControl("<img src=""graf2.aspx""/>")
frm.Controls.Add(lit)
.....

graf2.aspx
--------------------------------
Sub Page_Load(sender As Object, e As EventArgs)
Dim cok1 As New HttpCookie("cok1")
Dim cok2 As New HttpCookie("cok2")
Dim ja1, ja2 As String
Dim az,az2 As Integer
cok1 = Request.Cookies("cok1")
cok2 = Request.Cookies("cok2")
ja1 = cok1.Value
ja2 = cok2.Value
az = Convert.ToInt16(ja1) 'used in the graphic
az2 = Convert.ToInt16(ja2) 'used in the graphic
....
Dim objBitmap As New Bitmap(300, 200)
Dim objGraphic as Graphics = Graphics.FromImage(objBitmap)
etc ...
.......
end sub
 
S

Steve C. Orr [MCSD, MVP, CSM, ASP Insider]

I don't like cookies much; they're not very reliable.
I'd suggest you look into sending the parameters via QueryString instead.

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net
 

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

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top