diff --git a/src/ImageProcessor/Imaging/Filters/Artistic/HalftoneFilter.cs b/src/ImageProcessor/Imaging/Filters/Artistic/HalftoneFilter.cs
index a6b8cc7a15..1156435107 100644
--- a/src/ImageProcessor/Imaging/Filters/Artistic/HalftoneFilter.cs
+++ b/src/ImageProcessor/Imaging/Filters/Artistic/HalftoneFilter.cs
@@ -149,7 +149,7 @@ namespace ImageProcessor.Imaging.Filters.Artistic
}
///
- /// Applies the filter. TODO: Make this class implement an interface?
+ /// Applies the halftone filter.
///
///
/// The to apply the filter to.
@@ -159,6 +159,7 @@ namespace ImageProcessor.Imaging.Filters.Artistic
///
public Bitmap ApplyFilter(Bitmap source)
{
+ // TODO: Make this class implement an interface?
Bitmap cyan = null;
Bitmap magenta = null;
Bitmap yellow = null;
diff --git a/src/ImageProcessor/Imaging/Filters/Artistic/OilPaintingFilter.cs b/src/ImageProcessor/Imaging/Filters/Artistic/OilPaintingFilter.cs
index e79d8b53cc..bc5bc7e113 100644
--- a/src/ImageProcessor/Imaging/Filters/Artistic/OilPaintingFilter.cs
+++ b/src/ImageProcessor/Imaging/Filters/Artistic/OilPaintingFilter.cs
@@ -85,7 +85,7 @@ namespace ImageProcessor.Imaging.Filters.Artistic
}
///
- /// Applies the filter. TODO: Make this class implement an interface?
+ /// Applies the oil painting filter.
///
///
/// The source.
@@ -95,6 +95,7 @@ namespace ImageProcessor.Imaging.Filters.Artistic
///
public Bitmap ApplyFilter(Bitmap source)
{
+ // TODO: Make this class implement an interface?
int width = source.Width;
int height = source.Height;
diff --git a/src/ImageProcessor/Imaging/Filters/Photo/ComicMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/Photo/ComicMatrixFilter.cs
index 54a578f191..a8f87fb069 100644
--- a/src/ImageProcessor/Imaging/Filters/Photo/ComicMatrixFilter.cs
+++ b/src/ImageProcessor/Imaging/Filters/Photo/ComicMatrixFilter.cs
@@ -13,10 +13,8 @@ namespace ImageProcessor.Imaging.Filters.Photo
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
- using System.Threading.Tasks;
using ImageProcessor.Imaging.Filters.Artistic;
- using ImageProcessor.Imaging.Filters.EdgeDetection;
using ImageProcessor.Imaging.Helpers;
///
@@ -68,7 +66,7 @@ namespace ImageProcessor.Imaging.Filters.Photo
// Draw the edges.
edgeBitmap = new Bitmap(width, height);
edgeBitmap.SetResolution(image.HorizontalResolution, image.VerticalResolution);
- edgeBitmap = Trace(image, edgeBitmap, 120);
+ edgeBitmap = Effects.Trace(image, edgeBitmap, 120);
using (Graphics graphics = Graphics.FromImage(highBitmap))
{
@@ -97,8 +95,7 @@ namespace ImageProcessor.Imaging.Filters.Photo
using (Graphics graphics = Graphics.FromImage(patternBitmap))
{
graphics.Clear(Color.Transparent);
- graphics.SmoothingMode = SmoothingMode.HighQuality;
-
+
for (int y = 0; y < height; y += 8)
{
for (int x = 0; x < width; x += 4)
@@ -170,64 +167,5 @@ namespace ImageProcessor.Imaging.Filters.Photo
return (Bitmap)image;
}
-
- ///
- /// Traces the edges of a given .
- /// TODO: Move this to another class.
- ///
- ///
- /// The source .
- ///
- ///
- /// The destination .
- ///
- ///
- /// The threshold (between 0 and 255).
- ///
- ///
- /// The a new instance of traced.
- ///
- 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);
-
- using (Bitmap temp = filter.Process2DFilter(source))
- {
- destination = new InvertMatrixFilter().TransformImage(temp, destination);
-
- // Darken it slightly to aid detection
- destination = Adjustments.Brightness(destination, -5);
- }
-
- // Loop through and replace any colors more white than the threshold
- // with a transparent one.
- using (FastBitmap destinationBitmap = new FastBitmap(destination))
- {
- Parallel.For(
- 0,
- height,
- y =>
- {
- for (int x = 0; x < width; x++)
- {
- // ReSharper disable AccessToDisposedClosure
- Color color = destinationBitmap.GetPixel(x, y);
- if (color.B >= threshold)
- {
- destinationBitmap.SetPixel(x, y, Color.Transparent);
- }
- // ReSharper restore AccessToDisposedClosure
- }
- });
- }
-
- // Darken it again to average out the color.
- destination = Adjustments.Brightness(destination, -5);
- return (Bitmap)destination;
- }
}
}
\ No newline at end of file
diff --git a/src/ImageProcessor/Imaging/Helpers/Effects.cs b/src/ImageProcessor/Imaging/Helpers/Effects.cs
index a8d9821fdb..9c37242146 100644
--- a/src/ImageProcessor/Imaging/Helpers/Effects.cs
+++ b/src/ImageProcessor/Imaging/Helpers/Effects.cs
@@ -15,6 +15,9 @@ namespace ImageProcessor.Imaging.Helpers
using System.Drawing.Drawing2D;
using System.Threading.Tasks;
+ using ImageProcessor.Imaging.Filters.EdgeDetection;
+ using ImageProcessor.Imaging.Filters.Photo;
+
///
/// Provides reusable effect methods to apply to images.
///
@@ -176,5 +179,63 @@ namespace ImageProcessor.Imaging.Helpers
toMask.Dispose();
return clear;
}
+
+ ///
+ /// Traces the edges of a given .
+ ///
+ ///
+ /// The source .
+ ///
+ ///
+ /// The destination .
+ ///
+ ///
+ /// The threshold (between 0 and 255).
+ ///
+ ///
+ /// The a new instance of traced.
+ ///
+ public 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);
+
+ using (Bitmap temp = filter.Process2DFilter(source))
+ {
+ destination = new InvertMatrixFilter().TransformImage(temp, destination);
+
+ // Darken it slightly to aid detection
+ destination = Adjustments.Brightness(destination, -5);
+ }
+
+ // Loop through and replace any colors more white than the threshold
+ // with a transparent one.
+ using (FastBitmap destinationBitmap = new FastBitmap(destination))
+ {
+ Parallel.For(
+ 0,
+ height,
+ y =>
+ {
+ for (int x = 0; x < width; x++)
+ {
+ // ReSharper disable AccessToDisposedClosure
+ Color color = destinationBitmap.GetPixel(x, y);
+ if (color.B >= threshold)
+ {
+ destinationBitmap.SetPixel(x, y, Color.Transparent);
+ }
+ // ReSharper restore AccessToDisposedClosure
+ }
+ });
+ }
+
+ // Darken it again to average out the color.
+ destination = Adjustments.Brightness(destination, -5);
+ return (Bitmap)destination;
+ }
}
}
diff --git a/src/ImageProcessor/Processors/Halftone.cs b/src/ImageProcessor/Processors/Halftone.cs
index 995f47cbce..0817766106 100644
--- a/src/ImageProcessor/Processors/Halftone.cs
+++ b/src/ImageProcessor/Processors/Halftone.cs
@@ -13,13 +13,9 @@ namespace ImageProcessor.Processors
using System;
using System.Collections.Generic;
using System.Drawing;
- using System.Threading.Tasks;
using ImageProcessor.Common.Exceptions;
- using ImageProcessor.Imaging;
using ImageProcessor.Imaging.Filters.Artistic;
- using ImageProcessor.Imaging.Filters.EdgeDetection;
- using ImageProcessor.Imaging.Filters.Photo;
using ImageProcessor.Imaging.Helpers;
///
@@ -83,7 +79,7 @@ namespace ImageProcessor.Processors
// Draw the edges.
edgeBitmap = new Bitmap(width, height);
edgeBitmap.SetResolution(image.HorizontalResolution, image.VerticalResolution);
- edgeBitmap = Trace(image, edgeBitmap, 120);
+ edgeBitmap = Effects.Trace(image, edgeBitmap, 120);
using (Graphics graphics = Graphics.FromImage(newImage))
{
@@ -122,64 +118,5 @@ namespace ImageProcessor.Processors
return image;
}
-
- ///
- /// Traces the edges of a given .
- /// TODO: Move this to another class.
- ///
- ///
- /// The source .
- ///
- ///
- /// The destination .
- ///
- ///
- /// The threshold (between 0 and 255).
- ///
- ///
- /// The a new instance of traced.
- ///
- 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);
-
- using (Bitmap temp = filter.Process2DFilter(source))
- {
- destination = new InvertMatrixFilter().TransformImage(temp, destination);
-
- // Darken it slightly to aid detection
- destination = Adjustments.Brightness(destination, -5);
- }
-
- // Loop through and replace any colors more white than the threshold
- // with a transparent one.
- using (FastBitmap destinationBitmap = new FastBitmap(destination))
- {
- Parallel.For(
- 0,
- height,
- y =>
- {
- for (int x = 0; x < width; x++)
- {
- // ReSharper disable AccessToDisposedClosure
- Color color = destinationBitmap.GetPixel(x, y);
- if (color.B >= threshold)
- {
- destinationBitmap.SetPixel(x, y, Color.Transparent);
- }
- // ReSharper restore AccessToDisposedClosure
- }
- });
- }
-
- // Darken it again to average out the color.
- destination = Adjustments.Brightness(destination, -5);
- return (Bitmap)destination;
- }
}
}