Browse Source

Initial API shift to use Image rather than Bitmap as param

Former-commit-id: 828db9be865d921897d269456b65fb9d4aa5c94d
Former-commit-id: 572c0d146a899fcbdee65698e7f4a88368a39106
pull/17/head
James South 12 years ago
parent
commit
3eb7e66b3f
  1. 6
      src/ImageProcessor.Playground/Program.cs
  2. 4
      src/ImageProcessor/Imaging/FastBitmap.cs
  3. 4
      src/ImageProcessor/Imaging/Filters/EdgeDetection/ConvolutionFilter.cs
  4. 20
      src/ImageProcessor/Imaging/Filters/Photo/BlackWhiteMatrixFilter.cs
  5. 54
      src/ImageProcessor/Imaging/Filters/Photo/ComicMatrixFilter.cs
  6. 24
      src/ImageProcessor/Imaging/Filters/Photo/GothamMatrixFilter.cs
  7. 20
      src/ImageProcessor/Imaging/Filters/Photo/GreyScaleMatrixFilter.cs
  8. 20
      src/ImageProcessor/Imaging/Filters/Photo/HiSatchMatrixFilter.cs
  9. 8
      src/ImageProcessor/Imaging/Filters/Photo/IMatrixFilter.cs
  10. 20
      src/ImageProcessor/Imaging/Filters/Photo/InvertMatrixFilter.cs
  11. 20
      src/ImageProcessor/Imaging/Filters/Photo/LoSatchMatrixFilter.cs
  12. 22
      src/ImageProcessor/Imaging/Filters/Photo/LomographMatrixFilter.cs
  13. 4
      src/ImageProcessor/Imaging/Filters/Photo/MatrixFilterBase.cs
  14. 26
      src/ImageProcessor/Imaging/Filters/Photo/PolaroidMatrixFilter.cs
  15. 20
      src/ImageProcessor/Imaging/Filters/Photo/SepiaMatrixFilter.cs
  16. 12
      src/ImageProcessor/Imaging/Helpers/Adjustments.cs
  17. 10
      src/ImageProcessor/Imaging/Helpers/Effects.cs
  18. 1
      src/ImageProcessor/Processors/Brightness.cs
  19. 5
      src/ImageProcessor/Processors/EntropyCrop.cs
  20. 11
      src/ImageProcessor/Processors/Filter.cs
  21. 2
      src/ImageProcessor/Processors/Flip.cs

6
src/ImageProcessor.Playground/Program.cs

@ -76,11 +76,11 @@ namespace ImageProcessor.PlayGround
// .Constrain(size)
//.ReplaceColor(Color.FromArgb(255, 1, 107, 165), Color.FromArgb(255, 1, 165, 13), 80)
//.Resize(layer)
.DetectEdges(new SobelEdgeFilter(), false)
//.DetectEdges(new SobelEdgeFilter(), false)
//.DetectEdges(new LaplacianOfGaussianEdgeFilter())
//.EntropyCrop()
.Filter(MatrixFilters.Invert)
//.Filter(MatrixFilters.Comic)
//.Filter(MatrixFilters.Invert)
.Filter(MatrixFilters.Comic)
//.Filter(MatrixFilters.HiSatch)
//.Pixelate(8)
//.GaussianSharpen(10)

4
src/ImageProcessor/Imaging/FastBitmap.cs

@ -71,9 +71,9 @@ namespace ImageProcessor.Imaging
/// Initializes a new instance of the <see cref="FastBitmap"/> class.
/// </summary>
/// <param name="bitmap">The input bitmap.</param>
public FastBitmap(Bitmap bitmap)
public FastBitmap(Image bitmap)
{
this.bitmap = bitmap;
this.bitmap = (Bitmap)bitmap;
this.width = this.bitmap.Width;
this.height = this.bitmap.Height;
this.LockBitmap();

4
src/ImageProcessor/Imaging/Filters/EdgeDetection/ConvolutionFilter.cs

@ -53,7 +53,7 @@ namespace ImageProcessor.Imaging.Filters.EdgeDetection
/// </summary>
/// <param name="source">The image to process.</param>
/// <returns>A processed bitmap.</returns>
public Bitmap ProcessFilter(Bitmap source)
public Bitmap ProcessFilter(Image source)
{
int width = source.Width;
int height = source.Height;
@ -188,7 +188,7 @@ namespace ImageProcessor.Imaging.Filters.EdgeDetection
/// </summary>
/// <param name="source">The image to process.</param>
/// <returns>A processed bitmap.</returns>
public Bitmap Process2DFilter(Bitmap source)
public Bitmap Process2DFilter(Image source)
{
int width = source.Width;
int height = source.Height;

20
src/ImageProcessor/Imaging/Filters/Photo/BlackWhiteMatrixFilter.cs

@ -29,30 +29,26 @@ namespace ImageProcessor.Imaging.Filters.Photo
/// <summary>
/// Processes the image.
/// </summary>
/// <param name="image">The current image to process</param>
/// <param name="newImage">The new Image to return</param>
/// <param name="source">The current image to process</param>
/// <param name="destination">The new Image to return</param>
/// <returns>
/// The processed image.
/// The processed <see cref="System.Drawing.Bitmap"/>.
/// </returns>
public override Image TransformImage(Image image, Image newImage)
public override Bitmap TransformImage(Image source, Image destination)
{
using (Graphics graphics = Graphics.FromImage(newImage))
using (Graphics graphics = Graphics.FromImage(destination))
{
using (ImageAttributes attributes = new ImageAttributes())
{
attributes.SetColorMatrix(this.Matrix);
Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height);
Rectangle rectangle = new Rectangle(0, 0, source.Width, source.Height);
graphics.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
graphics.DrawImage(source, rectangle, 0, 0, source.Width, source.Height, GraphicsUnit.Pixel, attributes);
}
}
// Reassign the image.
image.Dispose();
image = newImage;
return image;
return (Bitmap)destination;
}
}
}

54
src/ImageProcessor/Imaging/Filters/Photo/ComicMatrixFilter.cs

@ -14,12 +14,11 @@ namespace ImageProcessor.Imaging.Filters.Photo
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using ImageProcessor.Common.Extensions;
using ImageProcessor.Imaging.Filters.Artistic;
using ImageProcessor.Imaging.Filters.EdgeDetection;
using ImageProcessor.Imaging.Helpers;
/// <summary>
/// Encapsulates methods with which to add a comic filter to an image.
@ -40,15 +39,17 @@ namespace ImageProcessor.Imaging.Filters.Photo
/// <param name="image">The current image to process</param>
/// <param name="newImage">The new Image to return</param>
/// <returns>
/// The processed image.
/// The processed <see cref="System.Drawing.Bitmap"/>.
/// </returns>
public override Image TransformImage(Image image, Image newImage)
public override Bitmap TransformImage(Image image, Image newImage)
{
// Bitmaps for comic pattern
Bitmap highBitmap = null;
Bitmap lowBitmap = null;
Bitmap patternBitmap = null;
Bitmap edgeBitmap = null;
int width = image.Width;
int height = image.Height;
try
{
@ -65,7 +66,8 @@ namespace ImageProcessor.Imaging.Filters.Photo
highBitmap = new OilPaintingFilter(3, 5).ApplyFilter((Bitmap)image);
// Draw the edges.
edgeBitmap = Trace((Bitmap)image, 120);
edgeBitmap = new Bitmap(width, height);
edgeBitmap = Trace(image, edgeBitmap, 120);
using (Graphics graphics = Graphics.FromImage(highBitmap))
{
@ -163,37 +165,44 @@ namespace ImageProcessor.Imaging.Filters.Photo
}
}
return image;
return (Bitmap)image;
}
/// <summary>
/// Detects and draws edges.
/// TODO: Move this to another class and do edge detection.
/// Traces the edges of a given <see cref="Image"/>.
/// TODO: Move this to another class.
/// </summary>
/// <param name="source">
/// The source bitmap.
/// The source <see cref="Image"/>.
/// </param>
/// <param name="destination">
/// The destination <see cref="Image"/>.
/// </param>
/// <param name="threshold">
/// The threshold.
/// The threshold (between 0 and 255).
/// </param>
/// <returns>
/// The <see cref="Bitmap"/>.
/// The a new instance of <see cref="Bitmap"/> traced.
/// </returns>
private static Bitmap Trace(Bitmap source, byte threshold = 0)
private static Bitmap Trace(Image source, Image destination, byte threshold = 0)
{
int width = source.Width;
int height = source.Height;
// Grab the edges converting to greyscale, and invert the colors.
ConvolutionFilter filter = new ConvolutionFilter(new SobelEdgeFilter(), true);
Bitmap destination = filter.Process2DFilter(source);
Bitmap invert = new Bitmap(width, height, PixelFormat.Format32bppArgb);
InvertMatrixFilter matrix = new InvertMatrixFilter();
invert = (Bitmap)matrix.TransformImage(destination, invert);
using (Bitmap temp = filter.Process2DFilter(source))
{
destination = new InvertMatrixFilter().TransformImage(temp, destination);
// Darken it slightly
destination = Adjustments.Brightness(destination, -5);
}
// Loop through and replace any colors more white than the threshold
// with a transparent one.
using (FastBitmap sourceBitmap = new FastBitmap(invert))
using (FastBitmap destinationBitmap = new FastBitmap(destination))
{
Parallel.For(
0,
@ -203,20 +212,17 @@ namespace ImageProcessor.Imaging.Filters.Photo
for (int x = 0; x < width; x++)
{
// ReSharper disable AccessToDisposedClosure
Color color = sourceBitmap.GetPixel(x, y);
Color color = destinationBitmap.GetPixel(x, y);
if (color.B >= threshold)
{
sourceBitmap.SetPixel(x, y, Color.Transparent);
destinationBitmap.SetPixel(x, y, Color.Transparent);
}
// ReSharper restore AccessToDisposedClosure
}
});
}
destination.Dispose();
destination = invert;
return destination;
return (Bitmap)destination;
}
/// <summary>
@ -231,7 +237,7 @@ namespace ImageProcessor.Imaging.Filters.Photo
/// <exception cref="ArgumentException">
/// Thrown if the two images are of different size.
/// </exception>
private static void ApplyMask(Bitmap source, Bitmap destination)
private static void ApplyMask(Image source, Image destination)
{
if (source.Size != destination.Size)
{

24
src/ImageProcessor/Imaging/Filters/Photo/GothamMatrixFilter.cs

@ -32,22 +32,22 @@ namespace ImageProcessor.Imaging.Filters.Photo
/// <summary>
/// Processes the image.
/// </summary>
/// <param name="image">The current image to process</param>
/// <param name="newImage">The new Image to return</param>
/// <param name="source">The current image to process</param>
/// <param name="destination">The new Image to return</param>
/// <returns>
/// The processed image.
/// The processed <see cref="System.Drawing.Bitmap"/>.
/// </returns>
public override Image TransformImage(Image image, Image newImage)
public override Bitmap TransformImage(Image source, Image destination)
{
using (Graphics graphics = Graphics.FromImage(newImage))
using (Graphics graphics = Graphics.FromImage(destination))
{
using (ImageAttributes attributes = new ImageAttributes())
{
attributes.SetColorMatrix(this.Matrix);
Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height);
Rectangle rectangle = new Rectangle(0, 0, source.Width, source.Height);
graphics.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
graphics.DrawImage(source, rectangle, 0, 0, source.Width, source.Height, GraphicsUnit.Pixel, attributes);
// Overlay the image with some semi-transparent colors to finish the effect.
using (GraphicsPath path = new GraphicsPath())
@ -72,14 +72,10 @@ namespace ImageProcessor.Imaging.Filters.Photo
}
// Add brightness and contrast to finish the effect.
newImage = Adjustments.Brightness((Bitmap)newImage, 5);
newImage = Adjustments.Contrast((Bitmap)newImage, 85);
destination = Adjustments.Brightness(destination, 5);
destination = Adjustments.Contrast(destination, 85);
// Reassign the image.
image.Dispose();
image = newImage;
return image;
return (Bitmap)destination;
}
}
}

20
src/ImageProcessor/Imaging/Filters/Photo/GreyScaleMatrixFilter.cs

@ -29,30 +29,26 @@ namespace ImageProcessor.Imaging.Filters.Photo
/// <summary>
/// Processes the image.
/// </summary>
/// <param name="image">The current image to process</param>
/// <param name="newImage">The new Image to return</param>
/// <param name="source">The current image to process</param>
/// <param name="destination">The new Image to return</param>
/// <returns>
/// The processed image.
/// The processed <see cref="System.Drawing.Bitmap"/>.
/// </returns>
public override Image TransformImage(Image image, Image newImage)
public override Bitmap TransformImage(Image source, Image destination)
{
using (Graphics graphics = Graphics.FromImage(newImage))
using (Graphics graphics = Graphics.FromImage(destination))
{
using (ImageAttributes attributes = new ImageAttributes())
{
attributes.SetColorMatrix(this.Matrix);
Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height);
Rectangle rectangle = new Rectangle(0, 0, source.Width, source.Height);
graphics.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
graphics.DrawImage(source, rectangle, 0, 0, source.Width, source.Height, GraphicsUnit.Pixel, attributes);
}
}
// Reassign the image.
image.Dispose();
image = newImage;
return image;
return (Bitmap)destination;
}
}
}

20
src/ImageProcessor/Imaging/Filters/Photo/HiSatchMatrixFilter.cs

@ -29,30 +29,26 @@ namespace ImageProcessor.Imaging.Filters.Photo
/// <summary>
/// Processes the image.
/// </summary>
/// <param name="image">The current image to process</param>
/// <param name="newImage">The new Image to return</param>
/// <param name="source">The current image to process</param>
/// <param name="destination">The new Image to return</param>
/// <returns>
/// The processed image.
/// The processed <see cref="System.Drawing.Bitmap"/>.
/// </returns>
public override Image TransformImage(Image image, Image newImage)
public override Bitmap TransformImage(Image source, Image destination)
{
using (Graphics graphics = Graphics.FromImage(newImage))
using (Graphics graphics = Graphics.FromImage(destination))
{
using (ImageAttributes attributes = new ImageAttributes())
{
attributes.SetColorMatrix(this.Matrix);
Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height);
Rectangle rectangle = new Rectangle(0, 0, source.Width, source.Height);
graphics.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
graphics.DrawImage(source, rectangle, 0, 0, source.Width, source.Height, GraphicsUnit.Pixel, attributes);
}
}
// Reassign the image.
image.Dispose();
image = newImage;
return image;
return (Bitmap)destination;
}
}
}

8
src/ImageProcessor/Imaging/Filters/Photo/IMatrixFilter.cs

@ -26,11 +26,11 @@ namespace ImageProcessor.Imaging.Filters.Photo
/// <summary>
/// Processes the image.
/// </summary>
/// <param name="image">The current image to process</param>
/// <param name="newImage">The new Image to return</param>
/// <param name="source">The current image to process</param>
/// <param name="destination">The new Image to return</param>
/// <returns>
/// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
/// The processed <see cref="System.Drawing.Bitmap"/>.
/// </returns>
Image TransformImage(Image image, Image newImage);
Bitmap TransformImage(Image source, Image destination);
}
}

20
src/ImageProcessor/Imaging/Filters/Photo/InvertMatrixFilter.cs

@ -29,30 +29,26 @@ namespace ImageProcessor.Imaging.Filters.Photo
/// <summary>
/// Processes the image.
/// </summary>
/// <param name="image">The current image to process</param>
/// <param name="newImage">The new Image to return</param>
/// <param name="source">The current image to process</param>
/// <param name="destination">The new Image to return</param>
/// <returns>
/// The processed image.
/// The processed <see cref="System.Drawing.Bitmap"/>.
/// </returns>
public override Image TransformImage(Image image, Image newImage)
public override Bitmap TransformImage(Image source, Image destination)
{
using (Graphics graphics = Graphics.FromImage(newImage))
using (Graphics graphics = Graphics.FromImage(destination))
{
using (ImageAttributes attributes = new ImageAttributes())
{
attributes.SetColorMatrix(this.Matrix);
Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height);
Rectangle rectangle = new Rectangle(0, 0, source.Width, source.Height);
graphics.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
graphics.DrawImage(source, rectangle, 0, 0, source.Width, source.Height, GraphicsUnit.Pixel, attributes);
}
}
// Reassign the image.
image.Dispose();
image = newImage;
return image;
return (Bitmap)destination;
}
}
}

20
src/ImageProcessor/Imaging/Filters/Photo/LoSatchMatrixFilter.cs

@ -29,30 +29,26 @@ namespace ImageProcessor.Imaging.Filters.Photo
/// <summary>
/// Processes the image.
/// </summary>
/// <param name="image">The current image to process</param>
/// <param name="newImage">The new Image to return</param>
/// <param name="source">The current image to process</param>
/// <param name="destination">The new Image to return</param>
/// <returns>
/// The processed image.
/// The processed <see cref="System.Drawing.Bitmap"/>.
/// </returns>
public override Image TransformImage(Image image, Image newImage)
public override Bitmap TransformImage(Image source, Image destination)
{
using (Graphics graphics = Graphics.FromImage(newImage))
using (Graphics graphics = Graphics.FromImage(destination))
{
using (ImageAttributes attributes = new ImageAttributes())
{
attributes.SetColorMatrix(this.Matrix);
Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height);
Rectangle rectangle = new Rectangle(0, 0, source.Width, source.Height);
graphics.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
graphics.DrawImage(source, rectangle, 0, 0, source.Width, source.Height, GraphicsUnit.Pixel, attributes);
}
}
// Reassign the image.
image.Dispose();
image = newImage;
return image;
return (Bitmap)destination;
}
}
}

22
src/ImageProcessor/Imaging/Filters/Photo/LomographMatrixFilter.cs

@ -31,32 +31,28 @@ namespace ImageProcessor.Imaging.Filters.Photo
/// <summary>
/// Processes the image.
/// </summary>
/// <param name="image">The current image to process</param>
/// <param name="newImage">The new Image to return</param>
/// <param name="source">The current image to process</param>
/// <param name="destination">The new Image to return</param>
/// <returns>
/// The processed image.
/// The processed <see cref="System.Drawing.Bitmap"/>.
/// </returns>
public override Image TransformImage(Image image, Image newImage)
public override Bitmap TransformImage(Image source, Image destination)
{
using (Graphics graphics = Graphics.FromImage(newImage))
using (Graphics graphics = Graphics.FromImage(destination))
{
using (ImageAttributes attributes = new ImageAttributes())
{
attributes.SetColorMatrix(this.Matrix);
Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height);
graphics.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
Rectangle rectangle = new Rectangle(0, 0, source.Width, source.Height);
graphics.DrawImage(source, rectangle, 0, 0, source.Width, source.Height, GraphicsUnit.Pixel, attributes);
}
}
// Add a vignette to finish the effect.
newImage = Effects.Vignette((Bitmap)newImage, Color.Black);
destination = Effects.Vignette(destination, Color.Black);
// Reassign the image.
image.Dispose();
image = newImage;
return image;
return (Bitmap)destination;
}
}
}

4
src/ImageProcessor/Imaging/Filters/Photo/MatrixFilterBase.cs

@ -29,9 +29,9 @@ namespace ImageProcessor.Imaging.Filters.Photo
/// <param name="image">The current image to process</param>
/// <param name="newImage">The new Image to return</param>
/// <returns>
/// The processed image.
/// The processed <see cref="System.Drawing.Bitmap"/>.
/// </returns>
public abstract Image TransformImage(Image image, Image newImage);
public abstract Bitmap TransformImage(Image image, Image newImage);
/// <summary>
/// Determines whether the specified <see cref="IMatrixFilter" />, is equal to this instance.

26
src/ImageProcessor/Imaging/Filters/Photo/PolaroidMatrixFilter.cs

@ -31,39 +31,35 @@ namespace ImageProcessor.Imaging.Filters.Photo
/// <summary>
/// Processes the image.
/// </summary>
/// <param name="image">The current image to process</param>
/// <param name="newImage">The new Image to return</param>
/// <param name="source">The current image to process</param>
/// <param name="destination">The new Image to return</param>
/// <returns>
/// The processed image.
/// The processed <see cref="System.Drawing.Bitmap"/>.
/// </returns>
public override Image TransformImage(Image image, Image newImage)
public override Bitmap TransformImage(Image source, Image destination)
{
using (Graphics graphics = Graphics.FromImage(newImage))
using (Graphics graphics = Graphics.FromImage(destination))
{
using (ImageAttributes attributes = new ImageAttributes())
{
attributes.SetColorMatrix(this.Matrix);
Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height);
Rectangle rectangle = new Rectangle(0, 0, source.Width, source.Height);
graphics.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
graphics.DrawImage(source, rectangle, 0, 0, source.Width, source.Height, GraphicsUnit.Pixel, attributes);
}
}
// Fade the contrast
newImage = Adjustments.Contrast((Bitmap)newImage, -30);
destination = Adjustments.Contrast(destination, -25);
// Add a glow to the image.
newImage = Effects.Glow((Bitmap)newImage, Color.FromArgb(70, 255, 153, 102));
destination = Effects.Glow(destination, Color.FromArgb(70, 255, 153, 102));
// Add a vignette to finish the effect.
newImage = Effects.Vignette((Bitmap)newImage, Color.FromArgb(80, 0, 0));
destination = Effects.Vignette(destination, Color.FromArgb(80, 0, 0));
// Reassign the image.
image.Dispose();
image = newImage;
return image;
return (Bitmap)destination;
}
}
}

20
src/ImageProcessor/Imaging/Filters/Photo/SepiaMatrixFilter.cs

@ -29,30 +29,26 @@ namespace ImageProcessor.Imaging.Filters.Photo
/// <summary>
/// Processes the image.
/// </summary>
/// <param name="image">The current image to process</param>
/// <param name="newImage">The new Image to return</param>
/// <param name="source">The current image to process</param>
/// <param name="destination">The new Image to return</param>
/// <returns>
/// The processed image.
/// The processed <see cref="System.Drawing.Bitmap"/>.
/// </returns>
public override Image TransformImage(Image image, Image newImage)
public override Bitmap TransformImage(Image source, Image destination)
{
using (Graphics graphics = Graphics.FromImage(newImage))
using (Graphics graphics = Graphics.FromImage(destination))
{
using (ImageAttributes attributes = new ImageAttributes())
{
attributes.SetColorMatrix(this.Matrix);
Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height);
Rectangle rectangle = new Rectangle(0, 0, source.Width, source.Height);
graphics.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
graphics.DrawImage(source, rectangle, 0, 0, source.Width, source.Height, GraphicsUnit.Pixel, attributes);
}
}
// Reassign the image.
image.Dispose();
image = newImage;
return image;
return (Bitmap)destination;
}
}
}

12
src/ImageProcessor/Imaging/Helpers/Adjustments.cs

@ -23,7 +23,7 @@ namespace ImageProcessor.Imaging.Helpers
/// Adjusts the brightness component of the given image.
/// </summary>
/// <param name="source">
/// The <see cref="Bitmap"/> source to adjust.
/// The <see cref="Image"/> source to adjust.
/// </param>
/// <param name="threshold">
/// The threshold value between -100 and 100 for adjusting the brightness.
@ -36,7 +36,7 @@ namespace ImageProcessor.Imaging.Helpers
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown if the threshold value falls outside the acceptable range.
/// </exception>
public static Bitmap Brightness(Bitmap source, int threshold, Rectangle? rectangle = null)
public static Bitmap Brightness(Image source, int threshold, Rectangle? rectangle = null)
{
if (threshold > 100 || threshold < -100)
{
@ -66,14 +66,14 @@ namespace ImageProcessor.Imaging.Helpers
}
}
return source;
return (Bitmap)source;
}
/// <summary>
/// Adjusts the contrast component of the given image.
/// </summary>
/// <param name="source">
/// The <see cref="Bitmap"/> source to adjust.
/// The <see cref="Image"/> source to adjust.
/// </param>
/// <param name="threshold">
/// The threshold value between -100 and 100 for adjusting the contrast.
@ -86,7 +86,7 @@ namespace ImageProcessor.Imaging.Helpers
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown if the threshold value falls outside the acceptable range.
/// </exception>
public static Bitmap Contrast(Bitmap source, int threshold, Rectangle? rectangle = null)
public static Bitmap Contrast(Image source, int threshold, Rectangle? rectangle = null)
{
if (threshold > 100 || threshold < -100)
{
@ -120,7 +120,7 @@ namespace ImageProcessor.Imaging.Helpers
}
}
return source;
return (Bitmap)source;
}
}
}

10
src/ImageProcessor/Imaging/Helpers/Effects.cs

@ -23,7 +23,7 @@ namespace ImageProcessor.Imaging.Helpers
/// Adds a vignette effect to the source image based on the given color.
/// </summary>
/// <param name="source">
/// The <see cref="Bitmap"/> source.
/// The <see cref="Image"/> source.
/// </param>
/// <param name="baseColor">
/// <see cref="Color"/> to base the vignette on.
@ -38,7 +38,7 @@ namespace ImageProcessor.Imaging.Helpers
/// <returns>
/// The <see cref="Bitmap"/> with the vignette applied.
/// </returns>
public static Bitmap Vignette(Bitmap source, Color baseColor, Rectangle? rectangle = null, bool invert = false)
public static Bitmap Vignette(Image source, Color baseColor, Rectangle? rectangle = null, bool invert = false)
{
using (Graphics graphics = Graphics.FromImage(source))
{
@ -93,18 +93,18 @@ namespace ImageProcessor.Imaging.Helpers
}
}
return source;
return (Bitmap)source;
}
/// <summary>
/// Adds a diffused glow (inverted vignette) effect to the source image based on the given color.
/// </summary>
/// <param name="source">The <see cref="Bitmap"/> source.</param>
/// <param name="source">The <see cref="Image"/> source.</param>
/// <param name="baseColor"><see cref="Color"/> to base the vignette on.</param>
/// <param name="rectangle">The rectangle to define the bounds of the area to vignette. If null then the effect is applied
/// to the entire image.</param>
/// <returns>The <see cref="Bitmap"/> with the vignette applied.</returns>
public static Bitmap Glow(Bitmap source, Color baseColor, Rectangle? rectangle = null)
public static Bitmap Glow(Image source, Color baseColor, Rectangle? rectangle = null)
{
return Vignette(source, baseColor, rectangle, true);
}

1
src/ImageProcessor/Processors/Brightness.cs

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

5
src/ImageProcessor/Processors/EntropyCrop.cs

@ -11,7 +11,6 @@ namespace ImageProcessor.Processors
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using ImageProcessor.Common.Exceptions;
using ImageProcessor.Imaging;
@ -61,12 +60,12 @@ namespace ImageProcessor.Processors
try
{
// Detect the edges then strip out middle shades.
grey = new ConvolutionFilter(new SobelEdgeFilter(), true).Process2DFilter((Bitmap)image);
grey = new ConvolutionFilter(new SobelEdgeFilter(), true).Process2DFilter(image);
grey = new BinaryThreshold(threshold).ProcessFilter(grey);
Rectangle rectangle = this.FindBoundingBox(grey, 0);
newImage = new Bitmap(rectangle.Width, rectangle.Height, PixelFormat.Format32bppPArgb);
newImage = new Bitmap(rectangle.Width, rectangle.Height);
using (Graphics graphics = Graphics.FromImage(newImage))
{
graphics.DrawImage(

11
src/ImageProcessor/Processors/Filter.cs

@ -66,13 +66,12 @@ namespace ImageProcessor.Processors
try
{
newImage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppPArgb);
newImage = new Bitmap(image.Width, image.Height);
IMatrixFilter matrix = this.DynamicParameter;
if (matrix != null)
{
return matrix.TransformImage(image, newImage);
}
newImage = matrix.TransformImage(image, newImage);
image.Dispose();
image = newImage;
}
catch (Exception ex)
{

2
src/ImageProcessor/Processors/Flip.cs

@ -66,7 +66,7 @@ namespace ImageProcessor.Processors
{
RotateFlipType rotateFlipType = this.DynamicParameter;
newImage = (Bitmap)image.Clone();
newImage = new Bitmap(image);
// Flip
newImage.RotateFlip(rotateFlipType);

Loading…
Cancel
Save