コード例 #1
0
 public void PercentageDifferences_DifferentSize_ThrowsException()
 {
     using (var newBm = new Bitmap(500, 500))
     {
         using (var newBm2 = new Bitmap(200, 200))
         {
             Assert.Throws <ImageComparisonSizeDifferenceException>(
                 () => ImagingUtilities.PercentageDifference(newBm, newBm2, string.Empty));
         }
     }
 }
コード例 #2
0
        public void PercentageDifferences_DifferentImage_NoSave()
        {
            using (var newBm = new Bitmap(500, 500))
            {
                // define the crop size
                var targetSize = new Rectangle(125, 125, 125, 125);

                // fill in the crop to a solid colour
                using (var newGrapics = Graphics.FromImage(newBm))
                {
                    newGrapics.CompositingQuality = CompositingQuality.HighSpeed;
                    newGrapics.SmoothingMode      = SmoothingMode.HighSpeed;
                    newGrapics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                    SolidBrush brush           = new SolidBrush(Color.Red);
                    SolidBrush backgroundBrush = new SolidBrush(Color.Green);
                    newGrapics.FillRectangle(backgroundBrush, new Rectangle(0, 0, 500, 500));
                    newGrapics.FillRectangle(brush, targetSize);
                }

                using (var newBm2 = new Bitmap(500, 500))
                {
                    // define the crop size
                    var targetSize2 = new Rectangle(250, 250, 250, 250);

                    // fill in the crop to a solid colour
                    using (var newGrapics = Graphics.FromImage(newBm2))
                    {
                        newGrapics.CompositingQuality = CompositingQuality.HighSpeed;
                        newGrapics.SmoothingMode      = SmoothingMode.HighSpeed;
                        newGrapics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                        SolidBrush brush           = new SolidBrush(Color.Red);
                        SolidBrush backgroundBrush = new SolidBrush(Color.Green);
                        newGrapics.FillRectangle(backgroundBrush, new Rectangle(0, 0, 500, 500));
                        newGrapics.FillRectangle(brush, targetSize2);
                    }

                    var difference = ImagingUtilities.PercentageDifference(newBm, newBm2, string.Empty);
                    Assert.AreEqual(31.25, difference);
                }
            }
        }