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))
{
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)

8
src/ImageProcessor/Imaging/CropLayer.cs

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

6
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;

Loading…
Cancel
Save