Provides helpers for asserting
        public void ImageIsRotatedInsideAndResized()
        {
            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                using (Image original = imageFactory.Image.Copy())
                {
                    imageFactory.RotateBounded(45);

                    imageFactory.Image.Width.Should()
                    .NotBe(original.Width, "because the rotated image dimensions should have changed");
                    imageFactory.Image.Height.Should()
                    .NotBe(original.Height, "because the rotated image dimensions should have changed");

                    AssertionHelpers.AssertImagesAreDifferent(
                        original,
                        imageFactory.Image,
                        "because the inside image should have been rotated on {0}",
                        imageFactory.ImagePath);

                    imageFactory.Format(new JpegFormat()).Save(OutputPath + "rotateboundedresized-" + i++ + ".jpg");
                }
            }
        }
Exemple #2
0
        public void AlphaIsModified()
        {
            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();
                imageFactory.Alpha(50);

                if (imageFactory.CurrentImageFormat.GetType() == typeof(BitmapFormat))
                {
                    AssertionHelpers.AssertImagesAreIdentical(
                        original,
                        imageFactory.Image,
                        "because the alpha operation should not have been applied on {0}",
                        imageFactory.ImagePath);
                }
                else
                {
                    AssertionHelpers.AssertImagesAreDifferent(
                        original,
                        imageFactory.Image,
                        "because the alpha operation should have been applied on {0}",
                        imageFactory.ImagePath);
                }

                imageFactory.Format(new JpegFormat()).Save("./output/alpha-" + i++ + ".jpg");
            }
        }
        public void FilterIsApplied()
        {
            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();

                List <IMatrixFilter> filters = new List <IMatrixFilter>
                {
                    MatrixFilters.BlackWhite,
                    MatrixFilters.Comic,
                    MatrixFilters.Gotham,
                    MatrixFilters.GreyScale,
                    MatrixFilters.HiSatch,
                    MatrixFilters.Invert,
                    MatrixFilters.Lomograph,
                    MatrixFilters.LoSatch,
                    MatrixFilters.Polaroid,
                    MatrixFilters.Sepia
                };

                foreach (IMatrixFilter filter in filters)
                {
                    imageFactory.Filter(filter);
                    AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the filter operation should have been applied on {0}", imageFactory.ImagePath);
                    imageFactory.Reset();
                    AssertionHelpers.AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset");
                }
            }
        }
        public void AlphaIsModified()
        {
            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();
                imageFactory.Alpha(50);

                ISupportedImageFormat format = imageFactory.CurrentImageFormat;

                // The Image class does not support alpha transparency in bitmaps.
                if (format.GetType() == typeof(BitmapFormat))
                {
                    AssertionHelpers.AssertImagesAreIdentical(
                        original,
                        imageFactory.Image,
                        "because the alpha operation should not have been applied on {0}",
                        imageFactory.ImagePath);
                }
                else
                {
                    AssertionHelpers.AssertImagesAreDifferent(
                        original,
                        imageFactory.Image,
                        "because the alpha operation should have been applied on {0}",
                        imageFactory.ImagePath);
                }
            }
        }
        public void EdgeDetectionEffectIsApplied()
        {
            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();

                List <IEdgeFilter> filters = new List <IEdgeFilter>
                {
                    new KayyaliEdgeFilter(),
                    new KirschEdgeFilter(),
                    new Laplacian3X3EdgeFilter(),
                    new Laplacian5X5EdgeFilter(),
                    new LaplacianOfGaussianEdgeFilter(),
                    new PrewittEdgeFilter(),
                    new RobertsCrossEdgeFilter(),
                    new ScharrEdgeFilter(),
                    new SobelEdgeFilter()
                };

                foreach (IEdgeFilter filter in filters)
                {
                    imageFactory.DetectEdges(filter);
                    AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the edge operation should have been applied on {0}", imageFactory.ImagePath);
                    imageFactory.Reset();
                    AssertionHelpers.AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset");
                }
            }
        }
        public void ImageIsCroppedWithLayer()
        {
            int       i       = 0;
            const int MaxSize = 20;

            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                using (Image original = imageFactory.Image.Copy())
                {
                    imageFactory.Crop(new CropLayer(0, 0, MaxSize, MaxSize, CropMode.Pixels));
                    AssertionHelpers.AssertImagesAreDifferent(
                        original,
                        imageFactory.Image,
                        "because the layered crop operation should have been applied on {0}",
                        imageFactory.ImagePath);

                    imageFactory.Image.Width.Should()
                    .Be(MaxSize, "because the cropped image should be {0}x{0}", MaxSize);
                    imageFactory.Image.Height.Should()
                    .Be(MaxSize, "because the cropped image should be {0}x{0}", MaxSize);

                    imageFactory.Format(new JpegFormat()).Save(OutputPath + "croplayer-" + i++ + ".jpg");
                }
            }
        }
Exemple #7
0
        public void ResolutionIsApplied()
        {
            int i = 0;

            byte[] bytes = new ExifBitConverter().IsLittleEndian()
                ? new byte[] { 144, 1, 0, 0, 1, 0, 0, 0 }
                : new byte[] { 0, 0, 0, 1, 0, 0, 1, 144 };

            int horizontalKey = (int)ExifPropertyTag.XResolution;
            int verticalKey   = (int)ExifPropertyTag.YResolution;

            foreach (ImageFactory imageFactory in this.ListInputImagesWithMetadata())
            {
                Image original = (Image)imageFactory.Image.Clone();
                imageFactory.Resolution(400, 400);
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the resolution operation should have been applied on {0}", imageFactory.ImagePath);

                Assert.AreEqual(400, imageFactory.Image.HorizontalResolution);
                Assert.AreEqual(400, imageFactory.Image.VerticalResolution);

                if (imageFactory.PreserveExifData && imageFactory.ExifPropertyItems.Any())
                {
                    if (imageFactory.ExifPropertyItems.ContainsKey(horizontalKey) &&
                        imageFactory.ExifPropertyItems.ContainsKey(verticalKey))
                    {
                        PropertyItem horizontal = imageFactory.ExifPropertyItems[horizontalKey];
                        PropertyItem vertical   = imageFactory.ExifPropertyItems[verticalKey];
                        Assert.AreEqual(bytes, horizontal.Value);
                        Assert.AreEqual(bytes, vertical.Value);
                    }
                }

                imageFactory.Format(new JpegFormat()).Save("./output/resolution-" + i++ + ".jpg");
            }
        }
        public void EdgeDetectionEffectIsApplied()
        {
            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();

                List <IEdgeFilter> filters = new List <IEdgeFilter>
                {
                    new KayyaliEdgeFilter(),
                    new KirschEdgeFilter(),
                    new Laplacian3X3EdgeFilter(),
                    new Laplacian5X5EdgeFilter(),
                    new LaplacianOfGaussianEdgeFilter(),
                    new PrewittEdgeFilter(),
                    new RobertsCrossEdgeFilter(),
                    new ScharrEdgeFilter(),
                    new SobelEdgeFilter()
                };

                int j = 0;
                foreach (IEdgeFilter filter in filters)
                {
                    imageFactory.DetectEdges(filter);
                    AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the edge operation should have been applied on {0}", imageFactory.ImagePath);
                    imageFactory.Reset();
                    AssertionHelpers.AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset");

                    imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/edgefilter-" + j++.ToString() + "-image-" + i.ToString() + ".jpg");
                }

                i++;
            }
        }
 public void VignetteEffectIsApplied()
 {
     foreach (ImageFactory imageFactory in this.ListInputImages())
     {
         Image original = (Image)imageFactory.Image.Clone();
         imageFactory.Vignette(Color.FromKnownColor(KnownColor.AliceBlue));
         AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the vignette operation should have been applied on {0}", imageFactory.ImagePath);
     }
 }
 public void SaturationIsModified()
 {
     foreach (ImageFactory imageFactory in this.ListInputImages())
     {
         Image original = (Image)imageFactory.Image.Clone();
         imageFactory.Saturation(50);
         AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the saturation operation should have been applied on {0}", imageFactory.ImagePath);
     }
 }
 public void PixelateEffectIsApplied()
 {
     foreach (ImageFactory imageFactory in this.ListInputImages())
     {
         Image original = (Image)imageFactory.Image.Clone();
         imageFactory.Pixelate(8);
         AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the pixelate operation should have been applied on {0}", imageFactory.ImagePath);
     }
 }
 public void SharpenEffectIsApplied()
 {
     foreach (ImageFactory imageFactory in this.ListInputImages())
     {
         Image original = (Image)imageFactory.Image.Clone();
         imageFactory.GaussianSharpen(5);
         AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the sharpen operation should have been applied on {0}", imageFactory.ImagePath);
     }
 }
 public void ColorIsReplaced()
 {
     foreach (ImageFactory imageFactory in this.ListInputImages())
     {
         Image original = (Image)imageFactory.Image.Clone();
         imageFactory.ReplaceColor(Color.White, Color.Black, 90);
         AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the color replace operation should have been applied on {0}", imageFactory.ImagePath);
     }
 }
 public void RoundedCornersAreApplied()
 {
     foreach (ImageFactory imageFactory in this.ListInputImages())
     {
         Image original = (Image)imageFactory.Image.Clone();
         imageFactory.RoundedCorners(new RoundedCornerLayer(5));
         AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the rounded corners operation should have been applied on {0}", imageFactory.ImagePath);
     }
 }
        public void BackgroundColorIsChanged()
        {
            ImageFactory imageFactory = new ImageFactory();

            imageFactory.Load(@"Images\text.png");
            Image original = (Image)imageFactory.Image.Clone();

            imageFactory.BackgroundColor(Color.Yellow);
            AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the background color operation should have been applied on {0}", imageFactory.ImagePath);
        }
 public void SharpenWithLayerIsApplied()
 {
     foreach (ImageFactory imageFactory in this.ListInputImages())
     {
         Image original = (Image)imageFactory.Image.Clone();
         imageFactory.GaussianSharpen(new GaussianLayer {
             Sigma = 10, Size = 5, Threshold = 2
         });
         AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the layered sharpen operation should have been applied on {0}", imageFactory.ImagePath);
     }
 }
        public void ColorIsReplaced()
        {
            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();
                imageFactory.ReplaceColor(Color.White, Color.Black, 90);
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the color replace operation should have been applied on {0}", imageFactory.ImagePath);

                imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/colorreplace-" + i++.ToString() + ".jpg");
            }
        }
Exemple #18
0
        public void SharpenEffectIsApplied()
        {
            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();
                imageFactory.GaussianSharpen(5);
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the sharpen operation should have been applied on {0}", imageFactory.ImagePath);

                imageFactory.Format(new JpegFormat()).Save("./output/sharpen-" + i++ + ".jpg");
            }
        }
Exemple #19
0
        public void ContrastIsModified()
        {
            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();
                imageFactory.Contrast(50);
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the contrast operation should have been applied on {0}", imageFactory.ImagePath);

                imageFactory.Format(new JpegFormat()).Save("./output/contrast-" + i++ + ".jpg");
            }
        }
        public void RoundedCornersAreApplied()
        {
            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();
                imageFactory.RoundedCorners(new RoundedCornerLayer(5));
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the rounded corners operation should have been applied on {0}", imageFactory.ImagePath);

                imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/roundedcorners-" + i++.ToString() + ".jpg");
            }
        }
        public void TintIsModified()
        {
            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();
                imageFactory.Tint(Color.FromKnownColor(KnownColor.AliceBlue));
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the tint operation should have been applied on {0}", imageFactory.ImagePath);

                imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/tint-" + i++.ToString() + ".jpg");
            }
        }
        public void PixelateEffectIsApplied()
        {
            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();
                imageFactory.Pixelate(8);
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the pixelate operation should have been applied on {0}", imageFactory.ImagePath);

                imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/pixelate-" + i++.ToString() + ".jpg");
            }
        }
        public void BrightnessIsModified()
        {
            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();
                imageFactory.Brightness(50);
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the brightness operation should have been applied on {0}", imageFactory.ImagePath);

                imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/brightness-" + i++.ToString() + ".jpg");
            }
        }
        public void ImageIsCroppedWithLayer()
        {
            const int MaxSize = 20;

            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();
                imageFactory.Crop(new CropLayer(0, 0, MaxSize, MaxSize, CropMode.Pixels));
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the layered crop operation should have been applied on {0}", imageFactory.ImagePath);

                imageFactory.Image.Width.Should().Be(MaxSize, "because the cropped image should be {0}x{0}", MaxSize);
                imageFactory.Image.Height.Should().Be(MaxSize, "because the cropped image should be {0}x{0}", MaxSize);
            }
        }
Exemple #25
0
        public void ResizeIsApplied()
        {
            Size        stretchedSize = new Size(400, 400);
            ResizeLayer stretchLayer  = new ResizeLayer(stretchedSize, ResizeMode.Stretch);

            Size paddedSize = new Size(700, 700);
            // ReSharper disable once RedundantArgumentDefaultValue
            ResizeLayer paddedLayer = new ResizeLayer(paddedSize, ResizeMode.Pad);

            Size        cropSize  = new Size(600, 450);
            ResizeLayer cropLayer = new ResizeLayer(cropSize, ResizeMode.Crop);

            Size        minSize  = new Size(300, 300);
            ResizeLayer minLayer = new ResizeLayer(minSize, ResizeMode.Min);

            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();

                // First stretch
                imageFactory.Format(new JpegFormat()).Resize(stretchLayer);
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the resize operation should have been applied on {0}", imageFactory.ImagePath);

                Assert.AreEqual(imageFactory.Image.Size, stretchedSize);
                imageFactory.Save("./output/resize-stretch-" + i + ".jpg");

                // Check we padd correctly.
                imageFactory.Resize(paddedLayer);
                Assert.AreEqual(imageFactory.Image.Size, paddedSize);
                imageFactory.Save("./output/resize-padd-" + i + ".jpg");

                // Check we crop correctly.
                imageFactory.Resize(cropLayer);
                Assert.AreEqual(imageFactory.Image.Size, cropSize);
                imageFactory.Save("./output/resize-crop-" + i + ".jpg");

                // Check we min correctly using the shortest size.
                imageFactory.Resize(minLayer);
                Assert.AreEqual(imageFactory.Image.Size, new Size(400, 300));
                imageFactory.Save("./output/resize-crop-" + i + ".jpg");

                imageFactory.Reset();
                AssertionHelpers.AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset");

                imageFactory.Format(new JpegFormat()).Save("./output/resize-" + i + ".jpg");
            }
        }
        public void FilterIsApplied()
        {
            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages(".bmp"))
            {
                using (Image original = imageFactory.Image.Copy())
                {
                    List <IMatrixFilter> filters = new List <IMatrixFilter>
                    {
                        MatrixFilters.BlackWhite,
                        MatrixFilters.Comic,
                        MatrixFilters.Gotham,
                        MatrixFilters.GreyScale,
                        MatrixFilters.HiSatch,
                        MatrixFilters.Invert,
                        MatrixFilters.Lomograph,
                        MatrixFilters.LoSatch,
                        MatrixFilters.Polaroid,
                        MatrixFilters.Sepia
                    };

                    int j = 0;
                    foreach (IMatrixFilter filter in filters)
                    {
                        imageFactory.Filter(filter);

                        AssertionHelpers.AssertImagesAreDifferent(
                            original,
                            imageFactory.Image,
                            "because the {0} filter operation should have been applied on {1}",
                            filter.GetType().Name,
                            imageFactory.ImagePath);

                        imageFactory.Format(new JpegFormat())
                        .Save(OutputPath + "filter-" + j++ + "-image-" + i + ".jpg");

                        imageFactory.Reset();

                        AssertionHelpers.AssertImagesAreIdentical(
                            original,
                            imageFactory.Image,
                            "because the image should be reset");
                    }

                    i++;
                }
            }
        }
Exemple #27
0
        public void BlurWithLayerIsApplied()
        {
            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();
                imageFactory.GaussianBlur(new GaussianLayer {
                    Sigma = 10, Size = 5, Threshold = 2
                });
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the layered blur operation should have been applied on {0}", imageFactory.ImagePath);

                imageFactory.Format(new JpegFormat()).Save("./output/blurlayer-" + i++ + ".jpg");
            }
        }
        public void SharpenWithLayerIsApplied()
        {
            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();
                imageFactory.GaussianSharpen(new GaussianLayer {
                    Sigma = 10, Size = 5, Threshold = 2
                });
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the layered sharpen operation should have been applied on {0}", imageFactory.ImagePath);

                imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/sharpenlayer-" + i++.ToString() + ".jpg");
            }
        }
 public void WatermarkIsApplied()
 {
     foreach (ImageFactory imageFactory in this.ListInputImages())
     {
         Image original = (Image)imageFactory.Image.Clone();
         imageFactory.Watermark(new TextLayer
         {
             FontFamily = new FontFamily("Arial"),
             FontSize   = 10,
             Position   = new Point(10, 10),
             Text       = "Lorem ipsum dolor"
         });
         AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the watermark operation should have been applied on {0}", imageFactory.ImagePath);
     }
 }
        public void HueIsModified()
        {
            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();
                imageFactory.Hue(90);
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the hue operation should have been applied on {0}", imageFactory.ImagePath);

                imageFactory.Reset();
                AssertionHelpers.AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset");

                imageFactory.Hue(116, true);
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the hue+rotate operation should have been applied on {0}", imageFactory.ImagePath);
            }
        }