diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index 6dda570ff..4d905d3ba 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -396,7 +396,7 @@ namespace ImageProcessor.UnitTests { imageFactory.Load(file.FullName); Image original = (Image)imageFactory.Image.Clone(); - imageFactory.RoundedCorners(new Imaging.RoundedCornerLayer(5, true, true, true, true)); + imageFactory.RoundedCorners(new Imaging.RoundedCornerLayer(5)); Assert.AreNotEqual(original, imageFactory.Image); } } diff --git a/src/ImageProcessor.Web.UnitTests/RegularExpressionUnitTests.cs b/src/ImageProcessor.Web.UnitTests/RegularExpressionUnitTests.cs index e76c7b63a..de544edc1 100644 --- a/src/ImageProcessor.Web.UnitTests/RegularExpressionUnitTests.cs +++ b/src/ImageProcessor.Web.UnitTests/RegularExpressionUnitTests.cs @@ -311,7 +311,7 @@ namespace ImageProcessor.Web.UnitTests Dictionary data = new Dictionary { { - "roundedcorners=30", new RoundedCornerLayer(30, true, true, true, true) + "roundedcorners=30", new RoundedCornerLayer(30) }, { "roundedcorners=radius-26|tl-true|tr-false|bl-true|br-false", new RoundedCornerLayer(26, true, false, true, false) diff --git a/src/ImageProcessor.Web/Processors/RoundedCorners.cs b/src/ImageProcessor.Web/Processors/RoundedCorners.cs index 3965db3c3..001130c14 100644 --- a/src/ImageProcessor.Web/Processors/RoundedCorners.cs +++ b/src/ImageProcessor.Web/Processors/RoundedCorners.cs @@ -14,7 +14,6 @@ namespace ImageProcessor.Web.Processors using System.Text.RegularExpressions; using ImageProcessor.Imaging; using ImageProcessor.Processors; - using ImageProcessor.Web.Helpers; /// /// Encapsulates methods to add rounded corners to an image. @@ -104,12 +103,11 @@ namespace ImageProcessor.Web.Processors this.SortOrder = match.Index; RoundedCornerLayer roundedCornerLayer = new RoundedCornerLayer( - this.ParseRadius(queryString), - CommonParameterParserUtility.ParseColor(queryString), - this.ParseCorner(TopLeftRegex, queryString), - this.ParseCorner(TopRightRegex, queryString), - this.ParseCorner(BottomLeftRegex, queryString), - this.ParseCorner(BottomRightRegex, queryString)); + this.ParseRadius(queryString), + this.ParseCorner(TopLeftRegex, queryString), + this.ParseCorner(TopRightRegex, queryString), + this.ParseCorner(BottomLeftRegex, queryString), + this.ParseCorner(BottomRightRegex, queryString)); this.Processor.DynamicParameter = roundedCornerLayer; } diff --git a/src/ImageProcessor/Imaging/RoundedCornerLayer.cs b/src/ImageProcessor/Imaging/RoundedCornerLayer.cs index e12c144e6..19e514f77 100644 --- a/src/ImageProcessor/Imaging/RoundedCornerLayer.cs +++ b/src/ImageProcessor/Imaging/RoundedCornerLayer.cs @@ -10,65 +10,17 @@ namespace ImageProcessor.Imaging { - using System.Drawing; - /// /// Encapsulates the properties required to add rounded corners to an image. /// public class RoundedCornerLayer { - #region Constructors - /// - /// Initializes a new instance of the class. - /// - public RoundedCornerLayer() - { - this.Radius = 10; - this.BackgroundColor = Color.Transparent; - this.TopLeft = true; - this.TopRight = true; - this.BottomLeft = true; - this.BottomRight = true; - } - - /// - /// Initializes a new instance of the class. - /// - /// - /// The radius at which the corner will be done. - /// - /// - /// Set if top left is rounded - /// - /// - /// Set if top right is rounded - /// - /// - /// Set if bottom left is rounded - /// - /// - /// Set if bottom right is rounded - /// - public RoundedCornerLayer(int radius, bool topLeft, bool topRight, bool bottomLeft, bool bottomRight) - { - this.Radius = radius; - this.BackgroundColor = Color.Transparent; - this.TopLeft = topLeft; - this.TopRight = topRight; - this.BottomLeft = bottomLeft; - this.BottomRight = bottomRight; - } - /// /// Initializes a new instance of the class. /// /// /// The radius at which the corner will be done. /// - /// - /// The to set as the background color. - /// Used for image formats that do not support transparency - /// /// /// Set if top left is rounded /// @@ -81,16 +33,14 @@ namespace ImageProcessor.Imaging /// /// Set if bottom right is rounded /// - public RoundedCornerLayer(int radius, Color backgroundColor, bool topLeft, bool topRight, bool bottomLeft, bool bottomRight) + public RoundedCornerLayer(int radius, bool topLeft = true, bool topRight = true, bool bottomLeft = true, bool bottomRight = true) { this.Radius = radius; - this.BackgroundColor = backgroundColor; this.TopLeft = topLeft; this.TopRight = topRight; this.BottomLeft = bottomLeft; this.BottomRight = bottomRight; } - #endregion #region Properties /// @@ -98,11 +48,6 @@ namespace ImageProcessor.Imaging /// public int Radius { get; set; } - /// - /// Gets or sets the background color. - /// - public Color BackgroundColor { get; set; } - /// /// Gets or sets a value indicating whether top left corners are to be added. /// @@ -145,7 +90,7 @@ namespace ImageProcessor.Imaging return false; } - return this.Radius == rounded.Radius && this.BackgroundColor == rounded.BackgroundColor + return this.Radius == rounded.Radius && this.TopLeft == rounded.TopLeft && this.TopRight == rounded.TopRight && this.BottomLeft == rounded.BottomLeft && this.BottomRight == rounded.BottomRight; } @@ -158,7 +103,7 @@ namespace ImageProcessor.Imaging /// public override int GetHashCode() { - return this.Radius.GetHashCode() + this.BackgroundColor.GetHashCode() + + return this.Radius.GetHashCode() + this.TopLeft.GetHashCode() + this.TopRight.GetHashCode() + this.BottomLeft.GetHashCode() + this.BottomRight.GetHashCode(); } diff --git a/src/ImageProcessor/Processors/RoundedCorners.cs b/src/ImageProcessor/Processors/RoundedCorners.cs index 5df2367fe..97c0f6078 100644 --- a/src/ImageProcessor/Processors/RoundedCorners.cs +++ b/src/ImageProcessor/Processors/RoundedCorners.cs @@ -68,14 +68,13 @@ namespace ImageProcessor.Processors { RoundedCornerLayer roundedCornerLayer = this.DynamicParameter; int radius = roundedCornerLayer.Radius; - Color backgroundColor = roundedCornerLayer.BackgroundColor; bool topLeft = roundedCornerLayer.TopLeft; bool topRight = roundedCornerLayer.TopRight; bool bottomLeft = roundedCornerLayer.BottomLeft; bool bottomRight = roundedCornerLayer.BottomRight; // Create a rounded image. - newImage = this.RoundCornerImage(image, radius, backgroundColor, topLeft, topRight, bottomLeft, bottomRight); + newImage = this.RoundCornerImage(image, radius, topLeft, topRight, bottomLeft, bottomRight); image.Dispose(); image = newImage; @@ -98,13 +97,12 @@ namespace ImageProcessor.Processors /// /// The image to add corners too /// The radius of the corners. - /// The background color to fill an image with. /// If the top left corner will have a rounded corner? /// If the top right corner will have a rounded corner? /// If the bottom left corner will have a rounded corner? /// If the bottom right corner will have a rounded corner? /// The image with rounded corners. - private Bitmap RoundCornerImage(Image image, int cornerRadius, Color backgroundColor, bool topLeft = false, bool topRight = false, bool bottomLeft = false, bool bottomRight = false) + private Bitmap RoundCornerImage(Image image, int cornerRadius, bool topLeft = false, bool topRight = false, bool bottomLeft = false, bool bottomRight = false) { int width = image.Width; int height = image.Height; @@ -119,14 +117,9 @@ namespace ImageProcessor.Processors { // Reduce the jagged edge. graphics.SmoothingMode = SmoothingMode.HighQuality; - - // Contrary to everything I have read bicubic is producing the best results. graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; - graphics.CompositingQuality = CompositingQuality.HighSpeed; - - // Fill the background. - graphics.Clear(backgroundColor); + graphics.CompositingQuality = CompositingQuality.HighQuality; // Add rounded corners using (GraphicsPath path = new GraphicsPath())