// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) James South. // Licensed under the Apache License, Version 2.0. // // // Encapsulates the properties required to resize an image. // // -------------------------------------------------------------------------------------------------------------------- namespace ImageProcessor.Imaging { #region Using using System.Collections.Generic; using System.Drawing; using System.Linq; #endregion /// /// Encapsulates the properties required to resize an image. /// public class ResizeLayer { #region Constructors /// /// Initializes a new instance of the class. /// /// /// The containing the width and height to set the image to. /// /// /// The resize mode to apply to resized image. (Default ResizeMode.Pad) /// /// /// The to apply to resized image. (Default AnchorPosition.Center) /// /// /// Whether to allow up-scaling of images. (Default true) /// /// /// The center coordinates (Default null) /// /// /// The maximum size to resize an image to. /// Used to restrict resizing based on calculated resizing /// /// /// The range of sizes to restrict resizing an image to. /// Used to restrict resizing based on calculated resizing /// public ResizeLayer( Size size, ResizeMode resizeMode = ResizeMode.Pad, AnchorPosition anchorPosition = AnchorPosition.Center, bool upscale = true, float[] centerCoordinates = null, Size? maxSize = null, List restrictedSizes = null) { this.Size = size; this.Upscale = upscale; this.ResizeMode = resizeMode; this.AnchorPosition = anchorPosition; this.CenterCoordinates = centerCoordinates ?? new float[] { }; this.MaxSize = maxSize; this.RestrictedSizes = restrictedSizes ?? new List(); } #endregion #region Properties /// /// Gets or sets the size. /// public Size Size { get; set; } /// /// Gets or sets the max size. /// public Size? MaxSize { get; set; } /// /// Gets or sets the restricted range of sizes. to restrict resizing methods to. /// public List RestrictedSizes { get; set; } /// /// Gets or sets the resize mode. /// public ResizeMode ResizeMode { get; set; } /// /// Gets or sets the anchor position. /// public AnchorPosition AnchorPosition { get; set; } /// /// Gets or sets a value indicating whether to allow up-scaling of images. /// public bool Upscale { get; set; } /// /// Gets or sets the center coordinates. /// public float[] CenterCoordinates { get; set; } #endregion /// /// Returns a value that indicates whether the specified object is an /// object that is equivalent to /// this object. /// /// /// The object to test. /// /// /// True if the given object is an object that is equivalent to /// this object; otherwise, false. /// 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 != null && resizeLayer.CenterCoordinates != null && this.CenterCoordinates.SequenceEqual(resizeLayer.CenterCoordinates)) || (this.CenterCoordinates == resizeLayer.CenterCoordinates)) && this.MaxSize == resizeLayer.MaxSize && ((this.RestrictedSizes != null && resizeLayer.RestrictedSizes != null && this.RestrictedSizes.SequenceEqual(resizeLayer.RestrictedSizes)) || (this.RestrictedSizes == resizeLayer.RestrictedSizes)); } /// /// Returns the hash code for this instance. /// /// /// A 32-bit signed integer that is the hash code for this instance. /// public override int GetHashCode() { unchecked { int hashCode = this.Size.GetHashCode(); hashCode = (hashCode * 397) ^ this.MaxSize.GetHashCode(); hashCode = (hashCode * 397) ^ (this.RestrictedSizes != null ? this.RestrictedSizes.GetHashCode() : 0); 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; } } } }