Let me know if I understand your question correctly: You would like to compare two images and if there is a difference between them then show this difference by drawing rectangle around it.
If this is the only thing you are trying to achieve then I would not use any external libraries and instead I would just compare the images pixel by pixel and then draw a rectangle around the area that doesn't match.
Assuming the two images are the same size, you can use simple loops to get the coordinates of the pixel that is different:
//the images are loaded in Bitmap image1, image2;
for (int x = 0; x < image1.Width; x++)
{
for (int y = 0; y < image1.Height; y++)
{
if (image1.GetPixel(x, y) != image2.GetPixel(x, y))
{
posX = x; posY = y; //position of the pixel that is different
}
}
}
Then you just draw a rectangle around that pixel specified by posX
and posY
using DrawRectangle()
. If you want to detect all differences you can create an array of pixel coordinates, add item to it every time you discover a difference and afterwards draw rectangles around all of them.
I am afraid using GetPixel()
is pretty slow. If you are aiming for speed then I recommend using LockBits()
and UnlockBits()
for pixel manipulation (see MSDN Library).