"General error occurred in GDI +" when trying to use Image.Save

I am developing an Outlook 2010 add-in and loading an image from a serialized XML file. The image loads fine, and I can assign it to the pictureBox object in Winform without any problems. The object is stored in

[XmlIgnore]
public Bitmap Image
{
   get { return this.templateImage; }
   set { this.templateImage = value; }
 }

When I try to save a physical file to my hard drive, I do this:

string filePath = Path.Combine(dirPath, item.Id + ".jpg");
try
{
    item.Image.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (Exception e)
{
    Debug.WriteLine("DEBUG::LoadImages()::Error attempting to create image::" + e.Message);
}

and I get a general error that occurred in GDI +. I checked the write permissions in the folder and it has write permissions. I'm not sure what is wrong here. I also changed ImageFormat to bmp and png, etc., to make sure it was a conversion problem ... but it is not. Anyone suggest trying something?

+5
source share
6 answers

. : "3) , ( ).

, , item.Image GDI + dispose(). , , "Write". :

try
{
   using (Bitmap tempImage = new Bitmap(item.Image)) 
   {
      tempImage.Save(filePath, System.Drawing.Imaging.ImageFormat.Png);
   }    
}
catch (Exception e)
{
    Debug.WriteLine("DEBUG::LoadImages()::Error attempting to create image::" + e.Message);
}
+22

:

wmImg.Save(BrandImgPath,ImageFormat.Png);

BrandImgPath = "D:/XYZ/fileName;

:

D: XYZ. . , .

if (Directory.Exists(@"D:/XYZ")) return;

, - .

+7


1. , / ( !).
2. Server.MapPath
3. , . 4. . , . Microsoft "Generic GDI + Errror"!!!

+2

, , , GDI , , .

+1

, :

if (Directory.Exists(directory_path))
{
 image.SaveAs(directory_path + filename);
}

As gaffleck said, it would be nice if GDI + chose a more informative exception.

0
source

I had the same general exception, but then I gave write permission to IIS on the plesk parallel file manager. if you are on a Windows server, be sure to specify write permission for the IIS user who was IIS_IUSR on my server

also make sure the folder you are trying to save is correct as indicated in the comments above.

0
source

All Articles