我有以下代码比较两个图像并输出有多少像素不同。我试图弄清楚如何让它输出像素的 x 和 y 坐标。有人有想法吗?
public int count2;
public Boolean flag;
private void button1_Click(object sender, EventArgs e)
{
string img1_ref, img2_ref;
//this image is 10x10
Bitmap img1 = Properties.Resources.black;
//this image is a screenshot
Bitmap img2 = Properties.Resources.bigimg;
for (int i = 0; i < img1.Width; i++)
{
for (int j = 0; j < img1.Height; j++)
{
img1_ref = img1.GetPixel(i, j).ToString();
img2_ref = img2.GetPixel(i, j).ToString();
if (img1_ref != img2_ref)
{
count2++;
flag = false;
break;
}
}
}
if (flag == false)
MessageBox.Show(count2 + " wrong pixels found");
}
这些是图像,应该在大图像的中间找到黑色的小方块: