Last post Dec 18, 2005 02:49 AM by jeepzj
Dec 16, 2005 02:55 PM|ywb|LINK
I have a helper class that has a method to resize images. It takes the virtual path of an image and resize it to a specified dimension like this.
public void ResizeImageTest(string pathImage, int newDimension)
string pathImageOnDisk = System.Web.HttpContext.Current.Server.MapPath(pathImage);
System.IO.FileStream fs = new System.IO.FileStream(pathImageOnDisk, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite);
Image imageOriginal = Image.FromStream(fs);
using (Bitmap bitmapNewImage = new Bitmap(imageOriginal, newDimension, newDimension))
When I try to call this method, it will error out in the line of the "bitmapNewImage.Save" with this:
Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
However, it works fine if I save to a different file like this:
string pathDummyImageOnDisk = System.Web.HttpContext.Current.Server.MapPath("/images/dummyPic.jpg");
I have searched the web and found that my solution might be in here:
But I don't really understand the steps, such as how to create a new bitmap "with a pixel format of more than 8 bits-per-pixel (BPP)", how to "use the Graphics.FromImage() method to obtain a Graphics object for the second Bitmap", use "Marshal.Copy function
... to copy the image bits from the first Bitmap to the second Bitmap" etc.
I suppose I could save it as a dummy file, close the original and rename the dummy file back to the original's name, but I'm just thinking this isn't the best solution.
Dec 17, 2005 03:21 AM|jeepzj|LINK
Dec 17, 2005 10:34 AM|ywb|LINK
Dec 18, 2005 02:49 AM|jeepzj|LINK
Can you dispose the image object?
Maybe the Bitmap remains locked the object.