Help with writing System.drawing in server control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ThatsIT.net.au

    #1

    Help with writing System.drawing in server control

    I have this code that writes a pie chart in a asp.net page, but I want to
    use it in a server control.

    When I try I get a error on the last line "Response.Outpu tStream"
    Obviously there is no response object but how do I write it to screen?

    Dim objBitmap As New System.Drawing. Bitmap(400, 440)
    Dim objGraphics As System.Drawing. Graphics
    objGraphics = System.Drawing. Graphics.FromIm age(objBitmap)
    objGraphics.Cle ar(Drawing.Colo r.White)

    Dim p As New Drawing.Pen(Dra wing.Color.Yell ow, 0)
    Dim rect As New Drawing.Rectang le(10, 10, 280, 280)
    'objGraphics.Dr awEllipse(p, rect)

    Dim b1 As New Drawing.SolidBr ush(Drawing.Col or.Red)
    Dim b2 As New Drawing.SolidBr ush(Drawing.Col or.Green)
    Dim b3 As New Drawing.SolidBr ush(Drawing.Col or.Blue)
    objGraphics.Fil lPie(b1, rect, 0.0, 90.0)
    objGraphics.Fil lPie(b2, rect, 90.0, 60.0)
    objGraphics.Fil lPie(b3, rect, 150.0, 210.0)

    Dim fontfml As New
    Drawing.FontFam ily(Drawing.Tex t.GenericFontFa milies.Serif)
    Dim font As New Drawing.Font(fo ntfml, 14)
    Dim brush As New Drawing.SolidBr ush(Drawing.Col or.Black)
    objGraphics.Dra wString("Missy Mosley", font, brush, 100, 300)
    Dim i As Image = New Image

    Dim mStream As MemoryStream = New MemoryStream
    Dim httpApp As HttpApplication = New HttpApplication
    objBitmap.Save( Response.Output Stream,
    Drawing.Imaging .ImageFormat.Gi f)

  • Alberto Poblacion

    #2
    Re: Help with writing System.drawing in server control

    "ThatsIT.net.au " <me@workwrote in message
    news:6A66FA67-C646-4EC1-A6C8-BB8B24E1D2BF@mi crosoft.com...
    >I have this code that writes a pie chart in a asp.net page, but I want to
    >use it in a server control.
    >
    When I try I get a error on the last line "Response.Outpu tStream"
    Obviously there is no response object but how do I write it to screen?
    The server control is expected to produce some HTML that will be merged
    into the page that contains the control. You cannot directly serve to the
    page the bits that form the image, since HTML does not provide for an image
    to be embedded inside the page source.
    One thing that you can do is make your server control generate an <img
    ....tag into its TextWriter. The img will have a src attribute pointing to
    an .ashx handler, which is the one that contains your GDI+ code and writes
    the bits to its output.

    Comment

    • Nathan Sokalski

      #3
      Re: Help with writing System.drawing in server control

      To use a System.Drawing. Bitmap object on a Page, you basically need to
      create a separate Page that returns ContentType="im age/gif" (or whatever
      type of image you are creating). You then use that *.aspx file the same way
      you would use a regular *.gif file. I wish there was a way to build this
      into the Control itself also, but to the best of my knowledge there isn't,
      since HTML needs a value to assign to the img tag's src attribute (or
      wherever the image is going to be used). What you can do, however, is have
      this separate Page accept a querystring so that you can use the same file to
      create all your images so that you don't need to create a million extra
      Pages. Something else you can do, if there are a couple static *.gif files
      you will be using that you don't want the user to need to copy, is create a
      resource file (*.resx) with the images in it and then have a Page that
      simply loads one of them and writes it out the same way you would if you
      were generating the image. Yeah, it's not what we want for writing custom
      controls when we want to include images, but to the best of my knowledge,
      it's the best we have write now.
      --
      Nathan Sokalski
      njsokalski@hotm ail.com
      有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。


      "ThatsIT.net.au " <me@workwrote in message
      news:6A66FA67-C646-4EC1-A6C8-BB8B24E1D2BF@mi crosoft.com...
      >I have this code that writes a pie chart in a asp.net page, but I want to
      >use it in a server control.
      >
      When I try I get a error on the last line "Response.Outpu tStream"
      Obviously there is no response object but how do I write it to screen?
      >
      Dim objBitmap As New System.Drawing. Bitmap(400, 440)
      Dim objGraphics As System.Drawing. Graphics
      objGraphics = System.Drawing. Graphics.FromIm age(objBitmap)
      objGraphics.Cle ar(Drawing.Colo r.White)
      >
      Dim p As New Drawing.Pen(Dra wing.Color.Yell ow, 0)
      Dim rect As New Drawing.Rectang le(10, 10, 280, 280)
      'objGraphics.Dr awEllipse(p, rect)
      >
      Dim b1 As New Drawing.SolidBr ush(Drawing.Col or.Red)
      Dim b2 As New Drawing.SolidBr ush(Drawing.Col or.Green)
      Dim b3 As New Drawing.SolidBr ush(Drawing.Col or.Blue)
      objGraphics.Fil lPie(b1, rect, 0.0, 90.0)
      objGraphics.Fil lPie(b2, rect, 90.0, 60.0)
      objGraphics.Fil lPie(b3, rect, 150.0, 210.0)
      >
      Dim fontfml As New
      Drawing.FontFam ily(Drawing.Tex t.GenericFontFa milies.Serif)
      Dim font As New Drawing.Font(fo ntfml, 14)
      Dim brush As New Drawing.SolidBr ush(Drawing.Col or.Black)
      objGraphics.Dra wString("Missy Mosley", font, brush, 100, 300)
      Dim i As Image = New Image
      >
      Dim mStream As MemoryStream = New MemoryStream
      Dim httpApp As HttpApplication = New HttpApplication
      objBitmap.Save( Response.Output Stream,
      Drawing.Imaging .ImageFormat.Gi f)

      Comment

      Working...