I have a method, that is used to extract difference from parent image. It works fine, but the problem is, it eats more time. Please tell me a faster way..!!!
My Method:
public static Bitmap GetDifferences(this Image img1, Image img2)
{
Bitmap parentImage = (Bitmap)img1.GetGrayScaleVersion();
Bitmap comparer = (Bitmap)img2.GetGrayScaleVersion();
Bitmap difference = (Bitmap)img2;
difference.MakeTransparent(Color.Violet);
for (int y = 0; y < img1.Height; y++)
{
for (int x = 0; x < img1.Width; x++)
{
if ((parentImage.GetPixel(x, y).R - comparer.GetPixel(x, y).R) == 0)
{
difference.SetPixel(x, y, Color.Transparent);
}
}
}
return difference;
}
Dependency Method:
public static Image GetGrayScaleVersion(this Image original)
{
Bitmap newBitmap = new Bitmap(original.Width, original.Height);
Graphics g = Graphics.FromImage(newBitmap);
ImageAttributes attributes = new ImageAttributes();
attributes.SetColorMatrix(ColorMatrix);
g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height),
0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);
g.Dispose();
return newBitmap;
}