在GDI +在Bitmap.Save()使用SaveFileDialog后出现一般错误 [英] A Generic error occurs at GDI+ at Bitmap.Save() after using SaveFileDialog

查看:180
本文介绍了在GDI +在Bitmap.Save()使用SaveFileDialog后出现一般错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的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 +

A Generic Error occured at 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后出现一般错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆