📷 A modern, cross-platform, 2D Graphics library for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

134 lines
4.6 KiB

// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ResizeLayer.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// <summary>
// Encapsulates the properties required to resize an image.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Imaging
{
#region Using
using System.Drawing;
using System.Linq;
#endregion
/// <summary>
/// Encapsulates the properties required to resize an image.
/// </summary>
public class ResizeLayer
{
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="ResizeLayer"/> class.
/// </summary>
/// <param name="size">
/// The <see cref="T:System.Drawing.Size"/> containing the width and height to set the image to.
/// </param>
/// <param name="resizeMode">
/// The resize mode to apply to resized image. (Default ResizeMode.Pad)
/// </param>
/// <param name="anchorPosition">
/// The <see cref="AnchorPosition"/> to apply to resized image. (Default AnchorPosition.Center)
/// </param>
/// <param name="upscale">
/// Whether to allow up-scaling of images. (Default true)
/// </param>
/// <param name="centerCoordinates">
/// The center coordinates (Default null)
/// </param>
public ResizeLayer(
Size size,
ResizeMode resizeMode = ResizeMode.Pad,
AnchorPosition anchorPosition = AnchorPosition.Center,
bool upscale = true,
float[] centerCoordinates = null)
{
this.Size = size;
this.Upscale = upscale;
this.ResizeMode = resizeMode;
this.AnchorPosition = anchorPosition;
this.CenterCoordinates = centerCoordinates ?? new float[] { };
}
#endregion
#region Properties
/// <summary>
/// Gets or sets the size.
/// </summary>
public Size Size { get; set; }
/// <summary>
/// Gets or sets the resize mode.
/// </summary>
public ResizeMode ResizeMode { get; set; }
/// <summary>
/// Gets or sets the anchor position.
/// </summary>
public AnchorPosition AnchorPosition { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to allow up-scaling of images.
/// </summary>
public bool Upscale { get; set; }
/// <summary>
/// Gets or sets the center coordinates.
/// </summary>
public float[] CenterCoordinates { get; set; }
#endregion
/// <summary>
/// Returns a value that indicates whether the specified object is an
/// <see cref="ResizeLayer"/> object that is equivalent to
/// this <see cref="ResizeLayer"/> object.
/// </summary>
/// <param name="obj">
/// The object to test.
/// </param>
/// <returns>
/// True if the given object is an <see cref="ResizeLayer"/> object that is equivalent to
/// this <see cref="ResizeLayer"/> object; otherwise, false.
/// </returns>
public override bool Equals(object obj)
{
ResizeLayer resizeLayer = obj as ResizeLayer;
if (resizeLayer == null)
{
return false;
}
return this.Size == resizeLayer.Size
&& this.ResizeMode == resizeLayer.ResizeMode
&& this.AnchorPosition == resizeLayer.AnchorPosition
&& this.Upscale == resizeLayer.Upscale
&& this.CenterCoordinates.SequenceEqual(resizeLayer.CenterCoordinates);
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>
/// A 32-bit signed integer that is the hash code for this instance.
/// </returns>
public override int GetHashCode()
{
unchecked
{
int hashCode = this.Size.GetHashCode();
hashCode = (hashCode * 397) ^ (int)this.ResizeMode;
hashCode = (hashCode * 397) ^ (int)this.AnchorPosition;
hashCode = (hashCode * 397) ^ this.Upscale.GetHashCode();
hashCode = (hashCode * 397) ^ (this.CenterCoordinates != null ? this.CenterCoordinates.GetHashCode() : 0);
return hashCode;
}
}
}
}