Browse Source

Tweaking ReplaceColor and Overlay

Former-commit-id: 0e2634fe0a744093515b469c25cd25ea6c25662e
Former-commit-id: 5c8130cde256b6ce8095669d6814cd5b2de1a25d
pull/17/head
James South 11 years ago
parent
commit
fa094831ec
  1. 25
      src/ImageProcessor.Playground/Program.cs
  2. 2
      src/ImageProcessor.Web/Processors/ReplaceColor.cs
  3. 4
      src/ImageProcessor/ImageFactory.cs
  4. 4
      src/ImageProcessor/Processors/Overlay.cs
  5. 14
      src/ImageProcessor/Processors/ReplaceColor.cs

25
src/ImageProcessor.Playground/Program.cs

@ -50,10 +50,10 @@ namespace ImageProcessor.PlayGround
di.Create();
}
// Image mask = Image.FromFile(Path.Combine(resolvedPath, "mask2.png"));
Image overlay = Image.FromFile(Path.Combine(resolvedPath, "monster.png"));
Image mask = Image.FromFile(Path.Combine(resolvedPath, "mask.png"));
Image overlay = Image.FromFile(Path.Combine(resolvedPath, "imageprocessor.128.png"));
//FileInfo fileInfo = new FileInfo(Path.Combine(resolvedPath, "monster.png"));
IEnumerable<FileInfo> files = GetFilesByExtensions(di, ".png");
IEnumerable<FileInfo> files = GetFilesByExtensions(di, ".jpg");
//IEnumerable<FileInfo> files = GetFilesByExtensions(di, ".gif", ".webp", ".bmp", ".jpg", ".png", ".tif");
foreach (FileInfo fileInfo in files)
@ -78,12 +78,11 @@ namespace ImageProcessor.PlayGround
//};
// Load, resize, set the format and quality and save an image.
imageFactory.Load(inStream)
.Overlay(new ImageLayer
{
Image = overlay,
Size = size,
Opacity = 80
})
//.Overlay(new ImageLayer
// {
// Image = overlay,
// Opacity = 50
// })
//.Alpha(50)
//.BackgroundColor(Color.White)
//.Resize(new Size((int)(size.Width * 1.1), 0))
@ -93,7 +92,7 @@ namespace ImageProcessor.PlayGround
//.Mask(mask)
//.Format(new PngFormat())
//.BackgroundColor(Color.Cyan)
//.ReplaceColor(Color.FromArgb(255, 1, 107, 165), Color.FromArgb(255, 1, 165, 13), 80)
.ReplaceColor(Color.FromArgb(255, 223, 224), Color.FromArgb(121, 188, 255), 128)
//.Resize(size)
// .Resize(new ResizeLayer(size, ResizeMode.Max))
// .Resize(new ResizeLayer(size, ResizeMode.Stretch))
@ -107,8 +106,10 @@ namespace ImageProcessor.PlayGround
//.Filter(MatrixFilters.HiSatch)
//.Pixelate(8)
//.GaussianSharpen(10)
.Format(new PngFormat() { IsIndexed = true })
.Save(Path.GetFullPath(Path.Combine(Path.GetDirectoryName(path), @"..\..\images\output", fileInfo.Name)));
.Format(new PngFormat())
//.Format(new PngFormat() { IsIndexed = true })
//.Save(Path.GetFullPath(Path.Combine(Path.GetDirectoryName(path), @"..\..\images\output", fileInfo.Name)));
.Save(Path.GetFullPath(Path.Combine(Path.GetDirectoryName(path), @"..\..\images\output", Path.GetFileNameWithoutExtension(fileInfo.Name) + ".png")));
stopwatch.Stop();
}

2
src/ImageProcessor.Web/Processors/ReplaceColor.cs

@ -156,7 +156,7 @@ namespace ImageProcessor.Web.Processors
fuzziness = int.Parse(match.Value.Split('=')[1], CultureInfo.InvariantCulture);
}
return Math.Max(0, Math.Min(100, fuzziness));
return Math.Max(0, Math.Min(128, fuzziness));
}
}
}

4
src/ImageProcessor/ImageFactory.cs

@ -778,7 +778,7 @@ namespace ImageProcessor
/// The replacement <see cref="System.Drawing.Color"/>.
/// </param>
/// <param name="fuzziness">
/// A value between 0 and 100 with which to alter the target detection accuracy.
/// A value between 0 and 128 with which to alter the target detection accuracy.
/// </param>
/// <returns>
/// The <see cref="ImageFactory"/>.
@ -786,7 +786,7 @@ namespace ImageProcessor
public ImageFactory ReplaceColor(Color target, Color replacement, int fuzziness = 0)
{
// Sanitize the input.
if (fuzziness < 0 || fuzziness > 100)
if (fuzziness < 0 || fuzziness > 128)
{
fuzziness = 0;
}

4
src/ImageProcessor/Processors/Overlay.cs

@ -78,8 +78,8 @@ namespace ImageProcessor.Processors
Size size = imageLayer.Size;
int width = image.Width;
int height = image.Height;
int overlayWidth = size != Size.Empty ? Math.Min(image.Size.Width, size.Width) : image.Size.Width;
int overlayHeight = size != Size.Empty ? Math.Min(image.Size.Height, size.Height) : image.Size.Height;
int overlayWidth = size != Size.Empty ? Math.Min(image.Size.Width, size.Width) : Math.Min(image.Size.Width, overlay.Size.Width);
int overlayHeight = size != Size.Empty ? Math.Min(image.Size.Height, size.Height) : Math.Min(image.Size.Height, overlay.Size.Height);
Point? position = imageLayer.Position;
int opacity = imageLayer.Opacity;

14
src/ImageProcessor/Processors/ReplaceColor.cs

@ -87,11 +87,13 @@ namespace ImageProcessor.Processors
using (FastBitmap fastBitmap = new FastBitmap(newImage))
{
Parallel.For(
0,
height,
y =>
{
//Parallel.For(
// 0,
// height,
// y =>
// {
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
// Get the pixel color.
@ -124,7 +126,7 @@ namespace ImageProcessor.Processors
}
}
}
});
}//);
}
image.Dispose();

Loading…
Cancel
Save