diff --git a/src/ImageProcessor/ImageProcessor.csproj b/src/ImageProcessor/ImageProcessor.csproj index 032ccd13c7..52d2aa27aa 100644 --- a/src/ImageProcessor/ImageProcessor.csproj +++ b/src/ImageProcessor/ImageProcessor.csproj @@ -155,6 +155,7 @@ + diff --git a/src/ImageProcessor/Imaging/Helpers/ImageMaths.cs b/src/ImageProcessor/Imaging/Helpers/ImageMaths.cs new file mode 100644 index 0000000000..1d2ac60b08 --- /dev/null +++ b/src/ImageProcessor/Imaging/Helpers/ImageMaths.cs @@ -0,0 +1,62 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// Provides reusable mathematical methods to apply to images. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor.Imaging.Helpers +{ + using System.Drawing; + + /// + /// Provides reusable mathematical methods to apply to images. + /// + public class ImageMaths + { + /// + /// Gets the bounding from the given points. + /// + /// + /// The designating the top left position. + /// + /// + /// The designating the bottom right position. + /// + /// + /// The bounding . + /// + public Rectangle GetBoundingRectangle(Point topLeft, Point bottomRight) + { + return new Rectangle(topLeft.X, topLeft.Y, bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y); + } + + /// + /// Gets a centered within it's parent. + /// + /// + /// The parent . + /// + /// + /// The child . + /// + /// + /// The centered . + /// + public Rectangle CenteredRectangle(Rectangle parent, Rectangle child) + { + if (parent.Size.Width < child.Size.Width && parent.Size.Height < child.Size.Height) + { + return parent; + } + + int x = (parent.Width - child.Width) / 2; + int y = (parent.Height - child.Height) / 2; + + return new Rectangle(x, y, child.Width, child.Height); + } + } +} diff --git a/src/ImageProcessor/Processors/EntropyCrop.cs b/src/ImageProcessor/Processors/EntropyCrop.cs index 2cd3c2bd0b..19eb65e6a4 100644 --- a/src/ImageProcessor/Processors/EntropyCrop.cs +++ b/src/ImageProcessor/Processors/EntropyCrop.cs @@ -10,7 +10,6 @@ namespace ImageProcessor.Processors using System; using System.Collections.Generic; using System.Drawing; - using System.Drawing.Imaging; using ImageProcessor.Common.Exceptions; using ImageProcessor.Imaging;