0

例如,我有图 1 和图 2,它们的尺寸相同,只是图 2 在左上角有一个正方形。如何比较两张图片获取颜色已更改的每个像素的位置,然后绘制到每个像素?谢谢。

4

1 回答 1

1

我最近一直在玩图像,这就是我一直在做的事情:

using System.Drawing;
using System.Drawing.Imaging;

// Open your two pictures as Bitmaps
Bitmap im1 = (Bitmap)Bitmap.FromFile("file1.bmp");
Bitmap im2 = (Bitmap)Bitmap.FromFile("file2.bmp");

// Assuming they're the same size, loop through all the pixels
for (int y = 0; y < im1.Height; y++)
{
    for (int x = 0; x < im1.Width; x++)
    {
        // Get the color of the current pixel in each bitmap
        Color color1 = im1.GetPixel(x, y);
        Color color2 = im2.GetPixel(x, y);

        // Check if they're the same
        if (color1 != color2)
        {
            // If not, generate a color...
            Color myRed = Color.FromArgb(255, 0, 0);
            // .. and set the pixel in one of the bitmaps
            im1.SetPixel(x, y, myRed);
        }
    }
}
// Save the updated bitmap to a new file
im1.Save("newfile.bmp", ImageFormat.Bmp);

这可能不是你想要做的,但希望能给你一些关于如何开始的想法。

于 2012-12-17T08:18:43.740 回答