我正在编写一个 C# 程序来对图像中的像素进行一些扫描。这是一个我只打算运行 5 次的程序,所以不需要高效。
读取每个像素后,我想更改它的颜色并更新图像的显示,以便我可以看到扫描进度和发现的内容,但我无法显示任何内容。有没有人做过类似的事情或知道一个很好的例子?
编辑:我目前尝试使用的代码是。
void Main()
{
Bitmap b = new Bitmap(@"C:\test\RKB2.bmp");
Form f1 = new Form();
f1.Height = (b.Height /10);
f1.Width = (b.Width / 10);
PictureBox PB = new PictureBox();
PB.Image = (Image)(new Bitmap(b, new Size(b.Width, b.Height)));
PB.Size = new Size(b.Width /10, b.Height /10);
PB.SizeMode = PictureBoxSizeMode.StretchImage;
f1.Controls.Add(PB);
f1.Show();
for(int y = 0; y < b.Height; y++)
{
for(int x = 0; x < b.Width; x++)
{
if(b.GetPixel(x,y).R == 0 && b.GetPixel(x,y).G == 0 && b.GetPixel(x,y).B == 0)
{
//color is black
}
if(b.GetPixel(x,y).R == 255 && b.GetPixel(x,y).G == 255 && b.GetPixel(x,y).B == 255)
{
//color is white
Bitmap tes = (Bitmap)PB.Image;
tes.SetPixel(x, y, Color.Yellow);
PB.Image = tes;
}
}
}
}