From a9ea5175046604205d1ea25b05309f16a815f66c Mon Sep 17 00:00:00 2001 From: James South Date: Mon, 25 Aug 2014 11:41:02 +0100 Subject: [PATCH] Adding missing BackgroundColor method Former-commit-id: 508637b4ab5b6c7be2c9127f8535174e0fd205cf --- .../ImageFactoryUnitTests.cs | 28 +++++++++++++++---- src/ImageProcessor/ImageFactory.cs | 20 +++++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index c5f569a39..6dda570ff 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -125,7 +125,7 @@ namespace ImageProcessor.UnitTests } /// - /// Tests that a filter is really applied by checking that the image is modified + /// Tests that brightness changes is really applied by checking that the image is modified /// [Test] public void TestApplyEffectBrightness() @@ -143,7 +143,25 @@ namespace ImageProcessor.UnitTests } /// - /// Tests that a filter is really applied by checking that the image is modified + /// Tests that background color changes are really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectBackgroundColor() + { + foreach (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); + imageFactory.BackgroundColor(Color.Yellow); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + + /// + /// Tests that a contrast change is really applied by checking that the image is modified /// [Test] public void TestApplyEffectContrast() @@ -161,7 +179,7 @@ namespace ImageProcessor.UnitTests } /// - /// Tests that a filter is really applied by checking that the image is modified + /// Tests that a saturation change is really applied by checking that the image is modified /// [Test] public void TestApplyEffectSaturation() @@ -179,7 +197,7 @@ namespace ImageProcessor.UnitTests } /// - /// Tests that a filter is really applied by checking that the image is modified + /// Tests that a tint change is really applied by checking that the image is modified /// [Test] public void TestApplyEffectTint() @@ -197,7 +215,7 @@ namespace ImageProcessor.UnitTests } /// - /// Tests that a filter is really applied by checking that the image is modified + /// Tests that a vignette change is really applied by checking that the image is modified /// [Test] public void TestApplyEffectVignette() diff --git a/src/ImageProcessor/ImageFactory.cs b/src/ImageProcessor/ImageFactory.cs index 29b64cc22..ab4494956 100644 --- a/src/ImageProcessor/ImageFactory.cs +++ b/src/ImageProcessor/ImageFactory.cs @@ -332,6 +332,26 @@ namespace ImageProcessor return this; } + /// + /// Changes the background color of the current image. + /// + /// + /// The to paint the image with. + /// + /// + /// The current instance of the class. + /// + public ImageFactory BackgroundColor(Color color) + { + if (this.ShouldProcess) + { + BackgroundColor backgroundColor = new BackgroundColor { DynamicParameter = color }; + this.CurrentImageFormat.ApplyProcessor(backgroundColor.ProcessImage, this); + } + + return this; + } + /// /// Constrains the current image, resizing it to fit within the given dimensions whilst keeping its aspect ratio. ///