diff --git a/src/ImageProcessor.Playground/Program.cs b/src/ImageProcessor.Playground/Program.cs
index 1cc1aaf35..9a1d1021f 100644
--- a/src/ImageProcessor.Playground/Program.cs
+++ b/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)
diff --git a/src/ImageProcessor/Imaging/FastBitmap.cs b/src/ImageProcessor/Imaging/FastBitmap.cs
index 8b5fd8715..e1bfda574 100644
--- a/src/ImageProcessor/Imaging/FastBitmap.cs
+++ b/src/ImageProcessor/Imaging/FastBitmap.cs
@@ -71,9 +71,9 @@ namespace ImageProcessor.Imaging
/// Initializes a new instance of the class.
///
/// The input bitmap.
- 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();
diff --git a/src/ImageProcessor/Imaging/Filters/EdgeDetection/ConvolutionFilter.cs b/src/ImageProcessor/Imaging/Filters/EdgeDetection/ConvolutionFilter.cs
index 450262c55..5d0fc1e36 100644
--- a/src/ImageProcessor/Imaging/Filters/EdgeDetection/ConvolutionFilter.cs
+++ b/src/ImageProcessor/Imaging/Filters/EdgeDetection/ConvolutionFilter.cs
@@ -53,7 +53,7 @@ namespace ImageProcessor.Imaging.Filters.EdgeDetection
///
/// The image to process.
/// A processed bitmap.
- 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
///
/// The image to process.
/// A processed bitmap.
- public Bitmap Process2DFilter(Bitmap source)
+ public Bitmap Process2DFilter(Image source)
{
int width = source.Width;
int height = source.Height;
diff --git a/src/ImageProcessor/Imaging/Filters/Photo/BlackWhiteMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/Photo/BlackWhiteMatrixFilter.cs
index cf8d7f7a2..2f11cc931 100644
--- a/src/ImageProcessor/Imaging/Filters/Photo/BlackWhiteMatrixFilter.cs
+++ b/src/ImageProcessor/Imaging/Filters/Photo/BlackWhiteMatrixFilter.cs
@@ -29,30 +29,26 @@ namespace ImageProcessor.Imaging.Filters.Photo
///
/// Processes the image.
///
- /// The current image to process
- /// The new Image to return
+ /// The current image to process
+ /// The new Image to return
///
- /// The processed image.
+ /// The processed .
///
- 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;
}
}
}
diff --git a/src/ImageProcessor/Imaging/Filters/Photo/ComicMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/Photo/ComicMatrixFilter.cs
index 868a4d64e..4dc980ce0 100644
--- a/src/ImageProcessor/Imaging/Filters/Photo/ComicMatrixFilter.cs
+++ b/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;
///
/// Encapsulates methods with which to add a comic filter to an image.
@@ -40,15 +39,17 @@ namespace ImageProcessor.Imaging.Filters.Photo
/// The current image to process
/// The new Image to return
///
- /// The processed image.
+ /// The processed .
///
- 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;
}
///
- /// Detects and draws edges.
- /// TODO: Move this to another class and do edge detection.
+ /// Traces the edges of a given .
+ /// TODO: Move this to another class.
///
///
- /// The source bitmap.
+ /// The source .
+ ///
+ ///
+ /// The destination .
///
///
- /// The threshold.
+ /// The threshold (between 0 and 255).
///
///
- /// The .
+ /// The a new instance of traced.
///
- 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;
}
///
@@ -231,7 +237,7 @@ namespace ImageProcessor.Imaging.Filters.Photo
///
/// Thrown if the two images are of different size.
///
- private static void ApplyMask(Bitmap source, Bitmap destination)
+ private static void ApplyMask(Image source, Image destination)
{
if (source.Size != destination.Size)
{
diff --git a/src/ImageProcessor/Imaging/Filters/Photo/GothamMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/Photo/GothamMatrixFilter.cs
index debe24e91..66adcb440 100644
--- a/src/ImageProcessor/Imaging/Filters/Photo/GothamMatrixFilter.cs
+++ b/src/ImageProcessor/Imaging/Filters/Photo/GothamMatrixFilter.cs
@@ -32,22 +32,22 @@ namespace ImageProcessor.Imaging.Filters.Photo
///
/// Processes the image.
///
- /// The current image to process
- /// The new Image to return
+ /// The current image to process
+ /// The new Image to return
///
- /// The processed image.
+ /// The processed .
///
- 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;
}
}
}
diff --git a/src/ImageProcessor/Imaging/Filters/Photo/GreyScaleMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/Photo/GreyScaleMatrixFilter.cs
index db9b5cdfe..49ac84b86 100644
--- a/src/ImageProcessor/Imaging/Filters/Photo/GreyScaleMatrixFilter.cs
+++ b/src/ImageProcessor/Imaging/Filters/Photo/GreyScaleMatrixFilter.cs
@@ -29,30 +29,26 @@ namespace ImageProcessor.Imaging.Filters.Photo
///
/// Processes the image.
///
- /// The current image to process
- /// The new Image to return
+ /// The current image to process
+ /// The new Image to return
///
- /// The processed image.
+ /// The processed .
///
- 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;
}
}
}
diff --git a/src/ImageProcessor/Imaging/Filters/Photo/HiSatchMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/Photo/HiSatchMatrixFilter.cs
index ad1b621a2..421f49e94 100644
--- a/src/ImageProcessor/Imaging/Filters/Photo/HiSatchMatrixFilter.cs
+++ b/src/ImageProcessor/Imaging/Filters/Photo/HiSatchMatrixFilter.cs
@@ -29,30 +29,26 @@ namespace ImageProcessor.Imaging.Filters.Photo
///
/// Processes the image.
///
- /// The current image to process
- /// The new Image to return
+ /// The current image to process
+ /// The new Image to return
///
- /// The processed image.
+ /// The processed .
///
- 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;
}
}
}
\ No newline at end of file
diff --git a/src/ImageProcessor/Imaging/Filters/Photo/IMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/Photo/IMatrixFilter.cs
index 32f370355..e4508f94a 100644
--- a/src/ImageProcessor/Imaging/Filters/Photo/IMatrixFilter.cs
+++ b/src/ImageProcessor/Imaging/Filters/Photo/IMatrixFilter.cs
@@ -26,11 +26,11 @@ namespace ImageProcessor.Imaging.Filters.Photo
///
/// Processes the image.
///
- /// The current image to process
- /// The new Image to return
+ /// The current image to process
+ /// The new Image to return
///
- /// The processed image from the current instance of the class.
+ /// The processed .
///
- Image TransformImage(Image image, Image newImage);
+ Bitmap TransformImage(Image source, Image destination);
}
}
diff --git a/src/ImageProcessor/Imaging/Filters/Photo/InvertMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/Photo/InvertMatrixFilter.cs
index 08826159a..7cd944183 100644
--- a/src/ImageProcessor/Imaging/Filters/Photo/InvertMatrixFilter.cs
+++ b/src/ImageProcessor/Imaging/Filters/Photo/InvertMatrixFilter.cs
@@ -29,30 +29,26 @@ namespace ImageProcessor.Imaging.Filters.Photo
///
/// Processes the image.
///
- /// The current image to process
- /// The new Image to return
+ /// The current image to process
+ /// The new Image to return
///
- /// The processed image.
+ /// The processed .
///
- 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;
}
}
}
\ No newline at end of file
diff --git a/src/ImageProcessor/Imaging/Filters/Photo/LoSatchMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/Photo/LoSatchMatrixFilter.cs
index 5d0a603de..222a7c037 100644
--- a/src/ImageProcessor/Imaging/Filters/Photo/LoSatchMatrixFilter.cs
+++ b/src/ImageProcessor/Imaging/Filters/Photo/LoSatchMatrixFilter.cs
@@ -29,30 +29,26 @@ namespace ImageProcessor.Imaging.Filters.Photo
///
/// Processes the image.
///
- /// The current image to process
- /// The new Image to return
+ /// The current image to process
+ /// The new Image to return
///
- /// The processed image.
+ /// The processed .
///
- 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;
}
}
}
diff --git a/src/ImageProcessor/Imaging/Filters/Photo/LomographMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/Photo/LomographMatrixFilter.cs
index 1b26d2a70..b8ab58460 100644
--- a/src/ImageProcessor/Imaging/Filters/Photo/LomographMatrixFilter.cs
+++ b/src/ImageProcessor/Imaging/Filters/Photo/LomographMatrixFilter.cs
@@ -31,32 +31,28 @@ namespace ImageProcessor.Imaging.Filters.Photo
///
/// Processes the image.
///
- /// The current image to process
- /// The new Image to return
+ /// The current image to process
+ /// The new Image to return
///
- /// The processed image.
+ /// The processed .
///
- 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;
}
}
}
diff --git a/src/ImageProcessor/Imaging/Filters/Photo/MatrixFilterBase.cs b/src/ImageProcessor/Imaging/Filters/Photo/MatrixFilterBase.cs
index 83aa8d7bf..720f73c51 100644
--- a/src/ImageProcessor/Imaging/Filters/Photo/MatrixFilterBase.cs
+++ b/src/ImageProcessor/Imaging/Filters/Photo/MatrixFilterBase.cs
@@ -29,9 +29,9 @@ namespace ImageProcessor.Imaging.Filters.Photo
/// The current image to process
/// The new Image to return
///
- /// The processed image.
+ /// The processed .
///
- public abstract Image TransformImage(Image image, Image newImage);
+ public abstract Bitmap TransformImage(Image image, Image newImage);
///
/// Determines whether the specified , is equal to this instance.
diff --git a/src/ImageProcessor/Imaging/Filters/Photo/PolaroidMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/Photo/PolaroidMatrixFilter.cs
index 2a5cd617f..d652e6d91 100644
--- a/src/ImageProcessor/Imaging/Filters/Photo/PolaroidMatrixFilter.cs
+++ b/src/ImageProcessor/Imaging/Filters/Photo/PolaroidMatrixFilter.cs
@@ -31,39 +31,35 @@ namespace ImageProcessor.Imaging.Filters.Photo
///
/// Processes the image.
///
- /// The current image to process
- /// The new Image to return
+ /// The current image to process
+ /// The new Image to return
///
- /// The processed image.
+ /// The processed .
///
- 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;
}
}
}
diff --git a/src/ImageProcessor/Imaging/Filters/Photo/SepiaMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/Photo/SepiaMatrixFilter.cs
index ad6f2a87b..3c78b075b 100644
--- a/src/ImageProcessor/Imaging/Filters/Photo/SepiaMatrixFilter.cs
+++ b/src/ImageProcessor/Imaging/Filters/Photo/SepiaMatrixFilter.cs
@@ -29,30 +29,26 @@ namespace ImageProcessor.Imaging.Filters.Photo
///
/// Processes the image.
///
- /// The current image to process
- /// The new Image to return
+ /// The current image to process
+ /// The new Image to return
///
- /// The processed image.
+ /// The processed .
///
- 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;
}
}
}
\ No newline at end of file
diff --git a/src/ImageProcessor/Imaging/Helpers/Adjustments.cs b/src/ImageProcessor/Imaging/Helpers/Adjustments.cs
index a1d5c53be..245d2689e 100644
--- a/src/ImageProcessor/Imaging/Helpers/Adjustments.cs
+++ b/src/ImageProcessor/Imaging/Helpers/Adjustments.cs
@@ -23,7 +23,7 @@ namespace ImageProcessor.Imaging.Helpers
/// Adjusts the brightness component of the given image.
///
///
- /// The source to adjust.
+ /// The source to adjust.
///
///
/// The threshold value between -100 and 100 for adjusting the brightness.
@@ -36,7 +36,7 @@ namespace ImageProcessor.Imaging.Helpers
///
/// Thrown if the threshold value falls outside the acceptable range.
///
- 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;
}
///
/// Adjusts the contrast component of the given image.
///
///
- /// The source to adjust.
+ /// The source to adjust.
///
///
/// The threshold value between -100 and 100 for adjusting the contrast.
@@ -86,7 +86,7 @@ namespace ImageProcessor.Imaging.Helpers
///
/// Thrown if the threshold value falls outside the acceptable range.
///
- 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;
}
}
}
diff --git a/src/ImageProcessor/Imaging/Helpers/Effects.cs b/src/ImageProcessor/Imaging/Helpers/Effects.cs
index 1161caacb..3af918a21 100644
--- a/src/ImageProcessor/Imaging/Helpers/Effects.cs
+++ b/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.
///
///
- /// The source.
+ /// The source.
///
///
/// to base the vignette on.
@@ -38,7 +38,7 @@ namespace ImageProcessor.Imaging.Helpers
///
/// The with the vignette applied.
///
- 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;
}
///
/// Adds a diffused glow (inverted vignette) effect to the source image based on the given color.
///
- /// The source.
+ /// The source.
/// to base the vignette on.
/// The rectangle to define the bounds of the area to vignette. If null then the effect is applied
/// to the entire image.
/// The with the vignette applied.
- 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);
}
diff --git a/src/ImageProcessor/Processors/Brightness.cs b/src/ImageProcessor/Processors/Brightness.cs
index 8dd37aeb0..8e4b92e6d 100644
--- a/src/ImageProcessor/Processors/Brightness.cs
+++ b/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;
diff --git a/src/ImageProcessor/Processors/EntropyCrop.cs b/src/ImageProcessor/Processors/EntropyCrop.cs
index c14709e48..2cd3c2bd0 100644
--- a/src/ImageProcessor/Processors/EntropyCrop.cs
+++ b/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(
diff --git a/src/ImageProcessor/Processors/Filter.cs b/src/ImageProcessor/Processors/Filter.cs
index ff93a6fd3..69ed65a73 100644
--- a/src/ImageProcessor/Processors/Filter.cs
+++ b/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)
{
diff --git a/src/ImageProcessor/Processors/Flip.cs b/src/ImageProcessor/Processors/Flip.cs
index 839edc34d..21c4496e6 100644
--- a/src/ImageProcessor/Processors/Flip.cs
+++ b/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);