H
Harry Whitehouse
Hello!
I have some ASPX code which creates a JPEG file in response to a button
press. The JPEG file is contructed in memory (see below), stored to a JPEG
file on the server, and then dished-out on the following browser window.
Everything works, but if I try to do the process again, I get a message
saying that the JPEG image file is in use. I can only free it by restarting
Web services. (I can't even delete the file using Windows Explorer!)
Clearly, I must not be releasing this resource properly.
Can anyone see what I'm missing?
TIA
Harry
// Create the bitmap object to draw our label
chartBmp = new Bitmap(width, height);
// Create the Graphics object.
chartGraphics = Graphics.FromImage(chartBmp);
// Fill the background of our choice.
chartGraphics.FillRectangle(new SolidBrush(Color.White), 0, 0,
width,height);
// top horizontal
Point pt1 = new Point(0,0);
Point pt2 = new Point(width,0);
chartGraphics.DrawLine(Pens.Black,pt1,pt2);
String chartFile = Server.MapPath("images/LabelImage.jpg");
FileStream jpgFile = new FileStream(chartFile, FileMode.Create,
FileAccess.ReadWrite);
// Save the graphics as Jpeg file.
chartBmp.Save(jpgFile, ImageFormat.Jpeg);
Response.Clear();
chartBmp.Save(Response.OutputStream, ImageFormat.Jpeg);
Response.End();
jpgFile.Close();
chartGraphics.Dispose();
chartBmp.Dispose();
I have some ASPX code which creates a JPEG file in response to a button
press. The JPEG file is contructed in memory (see below), stored to a JPEG
file on the server, and then dished-out on the following browser window.
Everything works, but if I try to do the process again, I get a message
saying that the JPEG image file is in use. I can only free it by restarting
Web services. (I can't even delete the file using Windows Explorer!)
Clearly, I must not be releasing this resource properly.
Can anyone see what I'm missing?
TIA
Harry
// Create the bitmap object to draw our label
chartBmp = new Bitmap(width, height);
// Create the Graphics object.
chartGraphics = Graphics.FromImage(chartBmp);
// Fill the background of our choice.
chartGraphics.FillRectangle(new SolidBrush(Color.White), 0, 0,
width,height);
// top horizontal
Point pt1 = new Point(0,0);
Point pt2 = new Point(width,0);
chartGraphics.DrawLine(Pens.Black,pt1,pt2);
String chartFile = Server.MapPath("images/LabelImage.jpg");
FileStream jpgFile = new FileStream(chartFile, FileMode.Create,
FileAccess.ReadWrite);
// Save the graphics as Jpeg file.
chartBmp.Save(jpgFile, ImageFormat.Jpeg);
Response.Clear();
chartBmp.Save(Response.OutputStream, ImageFormat.Jpeg);
Response.End();
jpgFile.Close();
chartGraphics.Dispose();
chartBmp.Dispose();