Browse Source

Adding some helpers for Mask

Former-commit-id: d969389a44ba0315b1aae749ac56415a836ecfdd
Former-commit-id: 8dcbde421d92d9f54e4f3510ae7b9196608cfd69
af/merge-core
James South 12 years ago
parent
commit
77eb254dfb
  1. 1
      src/ImageProcessor/ImageProcessor.csproj
  2. 62
      src/ImageProcessor/Imaging/Helpers/ImageMaths.cs
  3. 1
      src/ImageProcessor/Processors/EntropyCrop.cs

1
src/ImageProcessor/ImageProcessor.csproj

@ -155,6 +155,7 @@
<Compile Include="Common\Exceptions\ImageFormatException.cs" />
<Compile Include="ImageFactory.cs" />
<Compile Include="Imaging\AnchorPosition.cs" />
<Compile Include="Imaging\Helpers\ImageMaths.cs" />
<Compile Include="Imaging\MetaData\ExifPropertyTagType.cs" />
<Compile Include="Imaging\Convolution.cs" />
<Compile Include="Imaging\CropLayer.cs" />

62
src/ImageProcessor/Imaging/Helpers/ImageMaths.cs

@ -0,0 +1,62 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ImageMaths.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// <summary>
// Provides reusable mathematical methods to apply to images.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Imaging.Helpers
{
using System.Drawing;
/// <summary>
/// Provides reusable mathematical methods to apply to images.
/// </summary>
public class ImageMaths
{
/// <summary>
/// Gets the bounding <see cref="Rectangle"/> from the given points.
/// </summary>
/// <param name="topLeft">
/// The <see cref="Point"/> designating the top left position.
/// </param>
/// <param name="bottomRight">
/// The <see cref="Point"/> designating the bottom right position.
/// </param>
/// <returns>
/// The bounding <see cref="Rectangle"/>.
/// </returns>
public Rectangle GetBoundingRectangle(Point topLeft, Point bottomRight)
{
return new Rectangle(topLeft.X, topLeft.Y, bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y);
}
/// <summary>
/// Gets a <see cref="Rectangle"/> centered within it's parent.
/// </summary>
/// <param name="parent">
/// The parent <see cref="Rectangle"/>.
/// </param>
/// <param name="child">
/// The child <see cref="Rectangle"/>.
/// </param>
/// <returns>
/// The centered <see cref="Rectangle"/>.
/// </returns>
public Rectangle CenteredRectangle(Rectangle parent, Rectangle child)
{
if (parent.Size.Width < child.Size.Width && parent.Size.Height < child.Size.Height)
{
return parent;
}
int x = (parent.Width - child.Width) / 2;
int y = (parent.Height - child.Height) / 2;
return new Rectangle(x, y, child.Width, child.Height);
}
}
}

1
src/ImageProcessor/Processors/EntropyCrop.cs

@ -10,7 +10,6 @@ namespace ImageProcessor.Processors
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using ImageProcessor.Common.Exceptions;
using ImageProcessor.Imaging;

Loading…
Cancel
Save