mirror of https://github.com/SixLabors/ImageSharp
8 changed files with 281 additions and 26 deletions
@ -0,0 +1,81 @@ |
|||||
|
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
// <copyright file="CropLayer.cs" company="James South">
|
||||
|
// Copyright (c) James South.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
// <summary>
|
||||
|
// Encapsulates the properties required to crop an image.
|
||||
|
// </summary>
|
||||
|
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
|
||||
|
namespace ImageProcessor.Imaging |
||||
|
{ |
||||
|
using System; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Encapsulates the properties required to crop an image.
|
||||
|
/// </summary>
|
||||
|
public class CropLayer |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="CropLayer"/> class.
|
||||
|
/// </summary>
|
||||
|
/// <param name="left">
|
||||
|
/// The left coordinate of the crop layer.
|
||||
|
/// </param>
|
||||
|
/// <param name="top">
|
||||
|
/// The top coordinate of the crop layer.
|
||||
|
/// </param>
|
||||
|
/// <param name="right">
|
||||
|
/// The right coordinate of the crop layer.
|
||||
|
/// </param>
|
||||
|
/// <param name="bottom">
|
||||
|
/// The bottom coordinate of the crop layer.
|
||||
|
/// </param>
|
||||
|
/// <param name="cropMode">
|
||||
|
/// The <see cref="CropMode"/>.
|
||||
|
/// </param>
|
||||
|
/// <remarks>
|
||||
|
/// If the <see cref="CropMode"/> is set to <value>CropMode.Percentage</value> then the four coordinates
|
||||
|
/// become percentages to reduce from each edge.
|
||||
|
/// </remarks>
|
||||
|
public CropLayer(float left, float top, float right, float bottom, CropMode cropMode = CropMode.Percentage) |
||||
|
{ |
||||
|
if (left < 0 || top < 0 || right < 0 || bottom < 0) |
||||
|
{ |
||||
|
throw new ArgumentOutOfRangeException(); |
||||
|
} |
||||
|
|
||||
|
this.Left = left; |
||||
|
this.Top = top; |
||||
|
this.Right = right; |
||||
|
this.Bottom = bottom; |
||||
|
this.CropMode = cropMode; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the left coordinate of the crop layer.
|
||||
|
/// </summary>
|
||||
|
public float Left { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the top coordinate of the crop layer.
|
||||
|
/// </summary>
|
||||
|
public float Top { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the right coordinate of the crop layer.
|
||||
|
/// </summary>
|
||||
|
public float Right { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the bottom coordinate of the crop layer.
|
||||
|
/// </summary>
|
||||
|
public float Bottom { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the <see cref="CropMode"/>.
|
||||
|
/// </summary>
|
||||
|
public CropMode CropMode { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
// <copyright file="CropMode.cs" company="James South">
|
||||
|
// Copyright (c) James South.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
// <summary>
|
||||
|
// Enumerated cop modes to apply to cropped images.
|
||||
|
// </summary>
|
||||
|
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
|
||||
|
namespace ImageProcessor.Imaging |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Enumerated cop modes to apply to cropped images.
|
||||
|
/// </summary>
|
||||
|
public enum CropMode |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Crops the image using the standard rectangle model of x, y, width, height.
|
||||
|
/// </summary>
|
||||
|
Pixels, |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Crops the image using percentages model left, top, right, bottom.
|
||||
|
/// </summary>
|
||||
|
Percentage |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue