模糊参考错误?

时间:2018-05-24 21:50:31

标签: c#

使用canny过滤器检测到最大轮廓后,我现在只想提取其中存在的内容。

Rectangle rect = CvInvoke.BoundingRectangle(contours[largest_contour_index]);            
Bitmap target = new Bitmap(rect.Width, rect.Height);

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

imageBox2.Image = imageInput;

我收到此错误:

  

错误CS0104'图形'是System.Drawing.Graphics'之间的模糊参考。和UnityEngine.Graphics'

任何想法如何解决?

2 个答案:

答案 0 :(得分:4)

其他答案是正确的;在这些情况下有用的另一种技术是在文件的顶部创建一个别名指令:

using SDGraphics = System.Drawing.Graphics;

现在你可以说SDGraphics通常会说Graphics,而且不会含糊不清。

答案 1 :(得分:2)

错误信息实际上非常重要。将图形更改为System.Drawing.Graphics以解决歧义。