Browse Source

Sanitise CropLayer to allow for whole numbers

Former-commit-id: ef91ec618803f88370b9e96a51e91139a69ff7eb
Former-commit-id: 4ad4a123a8425f37694e1ea70c30c70fe4ad9316
af/merge-core
James South 11 years ago
parent
commit
a373a9fcd2
  1. 4
      src/ImageProcessor.Playground/Program.cs
  2. 8
      src/ImageProcessor/Imaging/CropLayer.cs
  3. 6
      src/ImageProcessor/Processors/Crop.cs

4
src/ImageProcessor.Playground/Program.cs

@ -81,6 +81,7 @@ namespace ImageProcessor.PlayGround
using (ImageFactory imageFactory = new ImageFactory(true)) using (ImageFactory imageFactory = new ImageFactory(true))
{ {
Size size = new Size(1024, 0); Size size = new Size(1024, 0);
CropLayer cropLayer = new CropLayer(20, 20, 20, 20, ImageProcessor.Imaging.CropMode.Percentage);
//ResizeLayer layer = new ResizeLayer(size, ResizeMode.Max, AnchorPosition.Center, false); //ResizeLayer layer = new ResizeLayer(size, ResizeMode.Max, AnchorPosition.Center, false);
//ContentAwareResizeLayer layer = new ContentAwareResizeLayer(size) //ContentAwareResizeLayer layer = new ContentAwareResizeLayer(size)
@ -110,7 +111,8 @@ namespace ImageProcessor.PlayGround
//.DetectEdges(new LaplacianOfGaussianEdgeFilter()) //.DetectEdges(new LaplacianOfGaussianEdgeFilter())
//.EntropyCrop() //.EntropyCrop()
//.Halftone(true) //.Halftone(true)
.RotateBounded(150, false) //.RotateBounded(150, false)
.Crop(cropLayer)
//.Rotate(140) //.Rotate(140)
//.Filter(MatrixFilters.Invert) //.Filter(MatrixFilters.Invert)
//.Contrast(50) //.Contrast(50)

8
src/ImageProcessor/Imaging/CropLayer.cs

@ -21,16 +21,16 @@ namespace ImageProcessor.Imaging
/// Initializes a new instance of the <see cref="CropLayer"/> class. /// Initializes a new instance of the <see cref="CropLayer"/> class.
/// </summary> /// </summary>
/// <param name="left"> /// <param name="left">
/// The left coordinate of the crop layer. /// The left coordinate of the crop layer.
/// </param> /// </param>
/// <param name="top"> /// <param name="top">
/// The top coordinate of the crop layer. /// The top coordinate of the crop layer.
/// </param> /// </param>
/// <param name="right"> /// <param name="right">
/// The right coordinate of the crop layer. /// The right coordinate of the crop layer.
/// </param> /// </param>
/// <param name="bottom"> /// <param name="bottom">
/// The bottom coordinate of the crop layer. /// The bottom coordinate of the crop layer.
/// </param> /// </param>
/// <param name="cropMode"> /// <param name="cropMode">
/// The <see cref="CropMode"/>. /// The <see cref="CropMode"/>.

6
src/ImageProcessor/Processors/Crop.cs

@ -73,6 +73,12 @@ namespace ImageProcessor.Processors
if (cropLayer.CropMode == CropMode.Percentage) if (cropLayer.CropMode == CropMode.Percentage)
{ {
// Fix for whole numbers.
cropLayer.Left = cropLayer.Left > 1 ? cropLayer.Left / 100 : cropLayer.Left;
cropLayer.Right = cropLayer.Right > 1 ? cropLayer.Right / 100 : cropLayer.Right;
cropLayer.Top = cropLayer.Top > 1 ? cropLayer.Top / 100 : cropLayer.Top;
cropLayer.Bottom = cropLayer.Bottom > 1 ? cropLayer.Bottom / 100 : cropLayer.Bottom;
// Work out the percentages. // Work out the percentages.
float left = cropLayer.Left * sourceWidth; float left = cropLayer.Left * sourceWidth;
float top = cropLayer.Top * sourceHeight; float top = cropLayer.Top * sourceHeight;

Loading…
Cancel
Save