Exemplo n.º 1
0
        /// <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;
                    }
                }
            }
        }
Exemplo n.º 2
0
        unsafe private void Compare()
        {
            // Compare dimensions of images A and B
            if (bitmapComparatorBitmapA.Width != bitmapComparatorBitmapB.Width || bitmapComparatorBitmapA.Height != bitmapComparatorBitmapB.Height)
            {
                // We don't know how to compare Bitmaps of different sizes
                // Return info that Bitmaps dimensions are different
                bitmapComparatorResult = Result.DifferentSize;
            }
            else
            {
                int width  = bitmapComparatorBitmapA.Width;
                int height = bitmapComparatorBitmapA.Height;

                for (int y = 0; y < height; ++y)
                {
                    for (int x = 0; x < width; ++x)
                    {
                        if (bitmapComparatorBitmapA.GetPixel(x, y) != bitmapComparatorBitmapB.GetPixel(x, y))
                        {
                            // Set pixel to Cyan in difference image
                            bitmapComparatorDifference.SetPixel(x, y, true);
                        }
                    }
                }

                // Evaluate comparison result
                if (bitmapComparatorDifference.GetBitmapDifferenceMetric() > 0)
                {
                    bitmapComparatorResult = Result.DifferentColor;
                }
                else
                {
                    bitmapComparatorResult = Result.Identical;
                }
            }
        }