G
Guest
Hi,
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))
{
bitmapNewImage.Save(coreFile.GetPhysicalPath(pathImage),
imageOriginal.RawFormat);
}
}
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");
bitmapNewImage.Save(pathDummyImageOnDisk, imageOriginal.RawFormat);
I have searched the web and found that my solution might be in here:
http://support.microsoft.com/?id=814675
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" etc.
Any advice?
Thanks,
WB
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))
{
bitmapNewImage.Save(coreFile.GetPhysicalPath(pathImage),
imageOriginal.RawFormat);
}
}
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");
bitmapNewImage.Save(pathDummyImageOnDisk, imageOriginal.RawFormat);
I have searched the web and found that my solution might be in here:
http://support.microsoft.com/?id=814675
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" etc.
Any advice?
Thanks,
WB