private async void ImagesDifferenceAsync(Image firstImage, Image secondImage) { int width = BmpImage.Width; int height = BmpImage.Height; Bitmap first = (Bitmap)firstImage; Bitmap second = (Bitmap)secondImage; Bitmap diff = new Bitmap(width, height); RGBColor = new RGB(); ProgressValue = 0; ProgressMaximum = width * height; await Task.Run(() => { int r = 0, g = 0, b = 0; int multiplier = 6; for (int i = 0; i < width; ++i) { for (int j = 0; j < height; ++j) { r = (ColorType == 0 || ColorType == 1) ? Math.Abs(first.GetPixel(i, j).R - second.GetPixel(i, j).R) : 0; g = (ColorType == 0 || ColorType == 2) ? Math.Abs(first.GetPixel(i, j).G - second.GetPixel(i, j).G) : 0; b = (ColorType == 0 || ColorType == 3) ? Math.Abs(first.GetPixel(i, j).B - second.GetPixel(i, j).B) : 0; RGBColor.AppendRGB(r, g, b); r = r * multiplier; g = g * multiplier; b = b * multiplier; r = (r > 255) ? 255 : r; g = (g > 255) ? 255 : g; b = (b > 255) ? 255 : b; diff.SetPixel(i, j, Color.FromArgb(byte.MaxValue, r, g, b)); ProgressValue++; } } }); DisplayImage = Imaging.CreateBitmapSourceFromHBitmap(diff.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(width, height)); }