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

Discussion in 'ASP .Net' started by André, Nov 27, 2006.

  1. André

    André Guest

    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)
     
    André, Nov 27, 2006
    #1
    1. Advertising

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


    "André" <hjhhb@dd> wrote in message
    news:...
    > 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)
    >
    >
    >
     
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider], Nov 27, 2006
    #2
    1. Advertising

  3. André

    André Guest

    Thanks, i'll try

    "Steve C. Orr [MCSD, MVP, CSM, ASP Insider]" <> schreef in
    bericht news:...
    > 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
    >
    >
    > "André" <hjhhb@dd> wrote in message
    > news:...
    >> 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)
    >>
    >>
    >>

    >
     
    André, Nov 27, 2006
    #3
  4. André

    André Guest

    can send one cookie but not two to the 2nd file

    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




    "Steve C. Orr [MCSD, MVP, CSM, ASP Insider]" <> schreef in
    bericht news:...
    > 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
    >
    >
    > "André" <hjhhb@dd> wrote in message
    > news:...
    >> 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)
    >>
    >>
    >>

    >
     
    André, Nov 29, 2006
    #4
  5. Re: can send one cookie but not two to the 2nd file

    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


    "André" <hjhhb@dd> wrote in message
    news:O%23tcUE$...
    > 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
    >
    >
    >
    >
    > "Steve C. Orr [MCSD, MVP, CSM, ASP Insider]" <> schreef in
    > bericht news:...
    >> 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
    >>
    >>
    >> "André" <hjhhb@dd> wrote in message
    >> news:...
    >>> 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)
    >>>
    >>>
    >>>

    >>

    >
    >
     
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider], Nov 30, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lau Lei Cheong

    Page.Render do not render complete page

    Lau Lei Cheong, May 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,081
    Lau Lei Cheong
    May 15, 2004
  2. Jeronimo Bertran

    Image Render Page performing other tasks??

    Jeronimo Bertran, Oct 6, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    409
    Jeronimo Bertran
    Oct 7, 2004
  3. 50 SOMETHING GAL
    Replies:
    3
    Views:
    403
  4. André
    Replies:
    4
    Views:
    137
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
    Nov 30, 2006
  5. Glenn Gillen
    Replies:
    0
    Views:
    285
    Glenn Gillen
    Nov 17, 2006
Loading...

Share This Page