【问题标题】:System.Runtime.InteropServices.ExternalException: 'A generic error occurred in GDI+.'System.Runtime.InteropServices.ExternalException:“GDI+ 中发生一般错误。”
【发布时间】:2018-08-28 19:30:39
【问题描述】:

今天,我想用 C# 扫描一些二维码。因为,为什么不呢? 所以,我正在使用 Emgu(来自 NuGet 的包),当我尝试保存图像时,我收到了这个错误。

System.Runtime.InteropServices.ExternalException: 'A generic error occurred in GDI+.'

这是我正在使用的代码:

Capture capture = new Capture(); //create a camera capture
Bitmap image = capture.QueryFrame().Bitmap; //take a picture
image.Save((path + "data" + i.ToString() + ".jpg").Replace(" ", "_"));

这里有什么问题?

【问题讨论】:

  • 使用 Path.Combine 创建正确的文件路径和名称。那个“替换”看起来是错误的,因为它会改变路径,因为“i”可能是一个数字。
  • 您发布的哪一行会引发错误?向我们展示entire error message
  • System.Runtime.InteropServices.ExternalException HResult=0x80004005 消息=GDI+ 中出现一般错误。 Source=System.Drawing StackTrace:在 System.Drawing.Image.Save(字符串文件名,ImageCodecInfo 编码器,EncoderParameters encoderParams)在 System.Drawing.Image.Save(字符串文件名,ImageFormat 格式)在 System.Drawing.Image.Save(字符串文件名)在 C:\Users\dev\source\repos\Demo\Demo\Program.cs:第 24 行中的 Demo.Program.Main(String[] args)

标签: c# memory computer-vision


【解决方案1】:

跑过这个,发现我的问题通过在保存中指定格式解决了:

bmpImage.Save(filename,System.Drawing.Imaging.ImageFormat.Png);

【讨论】:

    【解决方案2】:

    修复一些路径错误:

    string path = Path.Combine(baseDirectory, "img" + i.ToString() + ".jpg");
    

    【讨论】:

    • 我在将保存命令运行到内存流而不是文件时遇到了同样的错误。所以我认为这不是路径错误。
    • 我不确定它为什么会出错。也许传入了无效的位图?我的“破解”工作只是尝试/捕获保存语句并重试捕获图像。
    猜你喜欢
    • 2014-09-14
    • 1970-01-01
    • 1970-01-01
    • 2014-05-07
    • 1970-01-01
    • 2010-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多