// --------------------------------------------------------------------------------------------------------------------
//
// 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.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)
///
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
///
/// Gets or sets the size.
///
public Size Size { 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.SequenceEqual(resizeLayer.CenterCoordinates);
}
///
/// 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) ^ (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;
}
}
}
}