// --------------------------------------------------------------------------------------------------------------------
//
// 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;
#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 to set as the background color.
/// Used for image formats that do not support transparency (Default transparent)
///
///
/// 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)
///
public ResizeLayer(
Size size,
Color? backgroundColor = null,
ResizeMode resizeMode = ResizeMode.Pad,
AnchorPosition anchorPosition = AnchorPosition.Center,
bool upscale = true)
{
this.Size = size;
this.Upscale = upscale;
this.BackgroundColor = backgroundColor ?? Color.Transparent;
this.ResizeMode = resizeMode;
this.AnchorPosition = anchorPosition;
}
#endregion
#region Properties
///
/// Gets or sets the size.
///
public Size Size { get; set; }
///
/// Gets or sets the background color.
///
public Color BackgroundColor { 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.BackgroundColor == resizeLayer.BackgroundColor
&& this.Upscale == resizeLayer.Upscale;
}
///
/// Returns a hash code value that represents this object.
///
///
/// A hash code that represents this object.
///
public override int GetHashCode()
{
return this.Size.GetHashCode() +
this.ResizeMode.GetHashCode() +
this.AnchorPosition.GetHashCode() +
this.BackgroundColor.GetHashCode() +
this.Upscale.GetHashCode();
}
}
}