diff --git a/src/ImageProcessor.Playground/Program.cs b/src/ImageProcessor.Playground/Program.cs index 6c8210e430..52e0157b77 100644 --- a/src/ImageProcessor.Playground/Program.cs +++ b/src/ImageProcessor.Playground/Program.cs @@ -81,6 +81,7 @@ namespace ImageProcessor.PlayGround using (ImageFactory imageFactory = new ImageFactory(true)) { 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); //ContentAwareResizeLayer layer = new ContentAwareResizeLayer(size) @@ -110,7 +111,8 @@ namespace ImageProcessor.PlayGround //.DetectEdges(new LaplacianOfGaussianEdgeFilter()) //.EntropyCrop() //.Halftone(true) - .RotateBounded(150, false) + //.RotateBounded(150, false) + .Crop(cropLayer) //.Rotate(140) //.Filter(MatrixFilters.Invert) //.Contrast(50) diff --git a/src/ImageProcessor/Imaging/CropLayer.cs b/src/ImageProcessor/Imaging/CropLayer.cs index 97da50d44b..a863ad6b24 100644 --- a/src/ImageProcessor/Imaging/CropLayer.cs +++ b/src/ImageProcessor/Imaging/CropLayer.cs @@ -21,16 +21,16 @@ namespace ImageProcessor.Imaging /// Initializes a new instance of the class. /// /// - /// The left coordinate of the crop layer. + /// The left coordinate of the crop layer. /// /// - /// The top coordinate of the crop layer. + /// The top coordinate of the crop layer. /// /// - /// The right coordinate of the crop layer. + /// The right coordinate of the crop layer. /// /// - /// The bottom coordinate of the crop layer. + /// The bottom coordinate of the crop layer. /// /// /// The . diff --git a/src/ImageProcessor/Processors/Crop.cs b/src/ImageProcessor/Processors/Crop.cs index d0cde184d5..dda79132be 100644 --- a/src/ImageProcessor/Processors/Crop.cs +++ b/src/ImageProcessor/Processors/Crop.cs @@ -73,6 +73,12 @@ namespace ImageProcessor.Processors 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. float left = cropLayer.Left * sourceWidth; float top = cropLayer.Top * sourceHeight;