Last post Sep 15, 2005 05:04 AM by cptOneEye
Sep 15, 2005 03:21 AM|cptOneEye|LINK
i want to open an image, cut out a part of it and save this to the same imagefile. The problem is that i can't write to the imagefile because it is still locked by GDI.
Here is the code:
// load original image
System.Drawing.Image originalImg = System.Drawing.Image.FromFile(imageurl);
// create temporary image
Bitmap t = new Bitmap(originalImg.Width,originalImg.Height);
Graphics g1 = Graphics.FromImage(t);
// write original image to temporary image
// close original image and give it free!
// create new image to draw the cropped image in
cropped = new Bitmap(boxwidth, boxheight);
// write cropped image to the new and empty image
Graphics g = Graphics.FromImage(cropped);
g.DrawImage(t, new Rectangle(0,0,cropped.Width,cropped.Height),xbox,ybox,cropped.Width,cropped.Height,GraphicsUnit.Pixel);
// overwrite original image with cropped image (GDI Exception occurs here!)
ImageHandler.saveBitmap(cropped, imageurl, 100);
What i make is to open the original image, write its content to a temporary image, and close the original afterwards with the Dispose(). Then i go on and do all the work with the temporary image. So the originalimage should already
be given free when i want to save the new image.
What do i make wrong? Does dispose() not really close the file?
thx and greetings
Sep 15, 2005 05:04 AM|cptOneEye|LINK