/// <summary> /// Constructor initializes and compares pixel-by-pixel two Bitmap objects with predefined BitmapDifference object /// </summary> /// <param name="a">First Bitmap object (will serve as base to display differences on)</param> /// <param name="b">Second Bitmap object which will be compared to the first</param> /// <param name="d">Predefined BitmapDifference object (can be used to accumulate differences from multiple comparisons)</param> public BitmapComparator(BitmapEditor a, BitmapEditor b, BitmapDifference d) { bitmapComparatorBitmapA = a; bitmapComparatorBitmapB = b; bitmapComparatorDifference = d; Compare(); }
/// <summary> /// Constructor initializes and compares pixel-by-pixel two Bitmap objects /// </summary> /// <param name="a">First Bitmap object (will serve as base to display differences on)</param> /// <param name="b">Second Bitmap object which will be compared to the first</param> public BitmapComparator(BitmapEditor a, BitmapEditor b) { bitmapComparatorBitmapA = a; bitmapComparatorBitmapB = b; bitmapComparatorDifference = new BitmapDifference(bitmapComparatorBitmapA); Compare(); }
private void Compare() { BitmapEditor bitmapPrevious = bitmapBatch[0]; BitmapEditor bitmapCurrent; for (int bitmapBatchIndex = 0; bitmapBatchIndex < bitmapBatch.Count; ++bitmapBatchIndex) { bitmapCurrent = bitmapBatch[bitmapBatchIndex]; BitmapComparator bitmapComparatorCurrent = new BitmapComparator(bitmapPrevious, bitmapCurrent, bitmapDifference); } }
/// <summary> /// Generates masked image where pixels marked as masked are highlighted. /// </summary> /// <returns></returns> public Bitmap GetBitmapMaskedImage() { // Bitmap difference is base on initial base image BitmapEditor maskedImage = new BitmapEditor(differenceBaseImage); // Set each Different pixel to specified difference color for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { // Pixels are different but not masked if (differenceMask[x, y]) { maskedImage.SetPixel(x, y, differenceMaskColor); } } } return(maskedImage); }
/// <summary> /// Adds information about which pixels should be ignored when marked as different. Those pixels /// won't be counted as different in GetBitmapDifferenceMetric() and GetBitmapDifferenceImage(). /// </summary> /// <param name="mask">Bitmap where pixels of Color.Cyan indicates which pixel should be masked.</param> public void AddMask(BitmapEditor mask) { // Check Bitmap size, we can't continue if sizes doesn't correspond if (mask.Width != width || mask.Height != height) { throw new Exception("Passed Bitmap has different size than initialized mask"); } // Fill mask definition according the passed Bitmap // (if pixel on Bitmap is of ignored color - differenceMaskColor - mark it as ignored) for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { if (mask.GetPixel(x, y) == differenceColor) { differenceMask[x, y] = true; } } } }