gpt4 book ai didi

c# - 我应该添加什么引用来修复 GetPixel 错误?

转载 作者:行者123 更新时间:2023-12-02 19:36:50 27 4
gpt4 key购买 nike

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

Error 1 'System.Drawing.Image' does not contain a definition for 'GetPixel' and no extension method 'GetPixel' accepting a first argument of type 'System.Drawing.Image' could be found (are you missing a using directive or an assembly reference?)

有人知道我需要做什么吗?

//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++;

最佳答案

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

关于c# - 我应该添加什么引用来修复 GetPixel 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21386919/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com