我应该添加什么参考来修复GetPixel错误?

Cow*_*Boy 2 c#

在我尝试编写一些代码时,我收到了这个错误:

错误1'System.Drawing.Image'不包含'GetPixel'的定义,也没有扩展方法'GetPixel'接受类型'System.Drawing.Image'的第一个参数(你是否缺少using指令或者装配参考?)

有谁知道我需要做什么?

//Create a Image-Object on which we can draw
Image bmp = new Bitmap(100, 100);
//Create the Graphics-Object to paint on the Bitmap
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.White);
g.DrawString(randomString, myFont, new SolidBrush(Color.Black), new PointF(0, 0));
pictureBox1.Image = bmp;
bmp.Save(@"CAPTCHA.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

var backgroundPixels = 0;

for (int x = 0; x < bmp.Width; x++)
  for (int y = 0; y < bmp.Height; y++)
    if (bmp.GetPixel(x, y) == Color.White)
      backgroundPixels++;
Run Code Online (Sandbox Code Playgroud)

Cur*_*and 6

GetPixel是Bitmap类的一个方法,而不是Image类.您可以通过向构造函数提供图像来实例化位图.问题不在于你的使用指令,而在于你正在使用错误的类.