Drawing a line in ASP.NET
-
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
-
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
Try adding:
Response.Clear();
Response.ContentType = "image/jpeg";before saving the image to the output stream.
-
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
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