且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

"发生在GDI +&QUOT一般性错误;试图使用Image.Save时

更新时间:2022-12-09 20:11:09

感谢您西门白石在评论回答这个问题。他说:3)确保文件不在使用的任何其他(包括你的code)。

Thank you to Simon Whitehead for answering this in the comments. He said, "3) Make sure the file is not in use by anything else (including your code)."

所以,问题是,我自己的code的使用item.Image对象,并且是preventing GDI +调用Dispose()方法就可以了。解决的办法是在对象复制到一个新的对象,然后使用该对象来写入。由此产生的code是如下:

So the problem was that my own code was using the item.Image object, and was preventing GDI+ to call the dispose() method on it. The solution was to copy the object into a new object, then use that object to "Write." The resulting code is as follows:

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);
}