0

たとえば、写真1と写真2がありますが、写真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 に答える