问题描述
我用下面的code与使用块内一些code座:
I use the following code block with some more code inside the using block:
using (System.Drawing.Bitmap tempImg =
(System.Drawing.Bitmap)tempObj.GetData(System.Windows.Forms.DataFormats.Bitmap))
{
// ...
tempImg.Save("..\\..\\testdata\\tempImg.bmp", ImageFormat.Bmp);
// ...
}
但我仍然得到错误:
But I still get the error:
一般性错误发生在GDI +
后,才做出一些动作是不相关的使用块内的code。在其他时候,这个效果很好。
另外,tempImg.bmp是一个临时文件,所以我using块本身中删除tempImg.bmp。
only after I make some action which is not related to the code inside the using block. In other times this works well.Also the tempImg.bmp is a temporary file, so I delete the tempImg.bmp within the using block itself.
由于tempImg是使用内部,所以它的处理,我觉得锁定问题应该得到解决。
Since the tempImg is inside the using and this it's disposed, I think the locking problem should be solved.
可有人请让我知道什么是这个code中的错误?
Can someone please let me know what is the mistake in this code?
编辑:为System.Drawing.Image
到 System.Drawing.Bitmap
的类型 tempImg
。
编辑:
我已经确定我得到的是只创建后SaveFileDialog和用户点击保存这个错误。
I have identified I get this error only after SaveFileDialog is created and user clicks on 'Save'.
推荐答案
最后我能找到什么是错在我的code,并想在这里提到它,因为我认为这可能是有用的人....
Finally I could find what was wrong in my code and would like to mention it here as I think it may be useful to someone....
正如我已经给在tempImg.Save相对路径,并在用户点击保存在SaveFileDialog,为tempImg.Save的实际路径后变成:
As I have given a relative path in tempImg.Save, and after the user clicks 'Save' in SaveFileDialog, the actual path for tempImg.Save become :
由SaveFileDialog +相对路径指定的路径
Path specified by SaveFileDialog + the relative path
自动
因此,如果路径不存在,出现此错误。
Thus if the path does not exist, this error occurs.
感谢每个人的答案。
这篇关于在GDI +在Bitmap.Save()使用SaveFileDialog后出现一般错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!