Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Drawing a line in ASP.NET

Drawing a line in ASP.NET

Scheduled Pinned Locked Moved C#
graphicscsharpasp-netwinformshelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    naglbitur
    wrote on last edited by
    #1

    Hi there. I am trying to learn how to use GDI+ in ASP. I made a simple webform with a button on it. When the button is pressed a line is supposed to be drawn but nothing happens. Can someone please help me out? Here is the code: private void Button1_Click(object sender, System.EventArgs e) { Pen p = new Pen(Color.Black,3); Bitmap bit = new Bitmap(400, 400); Graphics g = Graphics.FromImage(bit); g.DrawLine(p, 30, 30, 97, 97); bit.Save(Response.OutputStream, ImageFormat.Jpeg); bit.Dispose(); g.Dispose(); } I can´t figure out why this doesn´t work. Any help is very much appreciated. Thanks, FJ

    L G 2 Replies Last reply
    0
    • N naglbitur

      Hi there. I am trying to learn how to use GDI+ in ASP. I made a simple webform with a button on it. When the button is pressed a line is supposed to be drawn but nothing happens. Can someone please help me out? Here is the code: private void Button1_Click(object sender, System.EventArgs e) { Pen p = new Pen(Color.Black,3); Bitmap bit = new Bitmap(400, 400); Graphics g = Graphics.FromImage(bit); g.DrawLine(p, 30, 30, 97, 97); bit.Save(Response.OutputStream, ImageFormat.Jpeg); bit.Dispose(); g.Dispose(); } I can´t figure out why this doesn´t work. Any help is very much appreciated. Thanks, FJ

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Try adding:

      Response.Clear();
      Response.ContentType = "image/jpeg";

      before saving the image to the output stream.

      xacc.ide-0.1.3.2

      1 Reply Last reply
      0
      • N naglbitur

        Hi there. I am trying to learn how to use GDI+ in ASP. I made a simple webform with a button on it. When the button is pressed a line is supposed to be drawn but nothing happens. Can someone please help me out? Here is the code: private void Button1_Click(object sender, System.EventArgs e) { Pen p = new Pen(Color.Black,3); Bitmap bit = new Bitmap(400, 400); Graphics g = Graphics.FromImage(bit); g.DrawLine(p, 30, 30, 97, 97); bit.Save(Response.OutputStream, ImageFormat.Jpeg); bit.Dispose(); g.Dispose(); } I can´t figure out why this doesn´t work. Any help is very much appreciated. Thanks, FJ

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        Please don't cross post. Standard question #4: No, "nothing" never happens. Exactly what is happening? Does the button seem to work? Does the button do a postback? Is the page replaced by the image that you created? You are writing the image to the response stream in a button event, that doesn't really work very well. As you are not even calling Response.End, the image data will be followed by the HTML code for the page. --- b { font-weight: normal; } -- modified at 13:23 Saturday 25th March, 2006

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups