// --------------------------------------------------------------------------------------------------------------------
//
// 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.
///
public ResizeLayer(Size size)
{
this.Size = size;
this.ResizeMode = ResizeMode.Pad;
this.AnchorPosition = AnchorPosition.Center;
this.BackgroundColor = Color.Transparent;
}
///
/// Initializes a new instance of the class.
///
///
/// The containing the width and height to set the image to.
///
///
/// The to apply to resized image.
///
public ResizeLayer(Size size, ResizeMode resizeMode)
{
this.Size = size;
this.ResizeMode = resizeMode;
this.AnchorPosition = AnchorPosition.Center;
this.BackgroundColor = Color.Transparent;
}
///
/// Initializes a new instance of the class.
///
///
/// The containing the width and height to set the image to.
///
///
/// The to apply to resized image.
///
public ResizeLayer(Size size, AnchorPosition anchorPosition)
{
this.Size = size;
this.AnchorPosition = anchorPosition;
this.ResizeMode = ResizeMode.Pad;
this.BackgroundColor = Color.Transparent;
}
///
/// Initializes a new instance of the class.
///
///
/// The to set as the background color.
/// Used for image formats that do not support transparency
///
///
/// The resize mode to apply to resized image.
///
///
/// The to apply to resized image.
///
public ResizeLayer(Color backgroundColor, ResizeMode resizeMode = ResizeMode.Pad, AnchorPosition anchorPosition = AnchorPosition.Center)
{
this.BackgroundColor = backgroundColor;
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; }
#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;
}
///
/// 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();
}
}
}