A Generic error occurs at GDI+ at Bitmap.Save() after using SaveFileDialog

前端 未结 12 1520
情书的邮戳
情书的邮戳 2020-12-10 01:07

I use the following code block with some more code inside the using block:

using (System.Drawing.Bitmap tempImg =
       (System.Drawing.Bitmap)tempObj.GetDa         


        
相关标签:
12条回答
  • 2020-12-10 01:16

    In my case, i was saving the bitmap file on the same location as the source, So that's the problem. I save the bitmap to the new location and all fine now.

    0 讨论(0)
  • 2020-12-10 01:17

    This is usually an indicator that something else, potentially some other thread in your own application, already has the target file that you're trying to save locked at the file system level. If you look at the inner exception I believe it should mention this. If it's not directly in the InnerException Another way to confirm this (or discover what it might really be instead) is to turn on first chance exceptions in the debugger and watch for what exception is being thrown "underneath" Save and then being turned into this generic exception.

    0 讨论(0)
  • 2020-12-10 01:17

    In my case it was an ASP.NET application in which I replaced a single DLL, and I had to simply re-start the application pool after deployment. Then it worked fine.

    0 讨论(0)
  • 2020-12-10 01:19

    I am trying to save image from resource and it gives me too GDI error when I directly use the method Bitmap.Save(filepath). I think We can use the same below code for any other bitmap image by cloning it.

    Private void SaveResourceImage() {
        object resBmpObject = Resource.Image1.Clone();//Bitmap Image from resource file
        //object resBmpObject = anyBmpImage.clone(); //for image other than resource image
        Bitmap resBmpImage = (Bitmap)resBmpObject;
        resBmpImage.Save(destFilePath, System.Drawing.Imaging.ImageFormat.Png);
        resBmpImage.dispose();
    }
    
    0 讨论(0)
  • 2020-12-10 01:25

    A Generic error occurs at GDI+ at Bitmap.Save() is generally received when the folder is protected, or the file name is invalid.

    A common error is to forget to make a name and just write the folder name alone.

    0 讨论(0)
  • 2020-12-10 01:26

    Tried all the solutions given here, but in vain. Found the solution eventually.

    1. Dispose any Graphics applied on image: g.dispose();
    2. Make sure save path exists: System.IO.Directory.Exists(dir);
    0 讨论(0)
提交回复
热议问题