【问题标题】:Getting unhandled exception in using Graphics使用图形时出现未处理的异常
【发布时间】:2018-05-26 08:39:07
【问题描述】:

我在运行此代码时得到未处理的异常

using (Graphics g = Graphics.FromImage(target))
 {
   g.DrawImage(imageInput, new Rectangle(0, 0, target.Width, target.Height),
               rect, GraphicsUnit.Pixel);
 }

上面写着:

System.ArgumentNullException : '值不能为空。范围 名称:图片

有什么建议吗?

【问题讨论】:

  • 这里的目标是什么?无法根据您发布的代码做出决定,请您发布相关代码和完整的例外情况
  • 感谢您的帮助我更改了代码。我使用 ROI 从图像中提取我想要的部分。如果您要我发送旧的,我会的!

标签: c# visual-studio emgucv


【解决方案1】:

这是因为imageInputnullParameter name: image 是重要的部分。如果您查看DrawImage 的文档,您会发现它需要一个image 参数。这是传递给DrawImage 的第一个参数,对应于imageInput

因此,需要初始化imageInput

【讨论】:

  • 我已经这样做了:imageInput = new Image<Bgr, byte>(Openfile.FileName); imageBox1.Image = imageInput;
  • @Chaima Soltani imageInput 是什么图像格式?该构造函数 (new Image<Bgr, byte>(Openfile.FileName);) 是否生成有效的 .NET 映像,因为它不是标准映像? Image 这里不是 .NET System.Drawing.Image(抽象)类。
【解决方案2】:

您需要提供源图片; imageInput 不能为空。

【讨论】:

  • 已经完成:imageInput = new Image<Bgr, byte>(Openfile.FileName); imageBox1.Image = imageInput;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多