@ -30,8 +30,6 @@ namespace ImageProcessor.PlayGround
/// </summary>
public class Program
{
protected static readonly IEnumerable < ISupportedImageFormat > formats = ImageProcessorBootstrapper . Instance . SupportedImageFormats ;
/// <summary>
/// The main routine.
/// </summary>
@ -50,75 +48,78 @@ namespace ImageProcessor.PlayGround
di . Create ( ) ;
}
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"));
// 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 , "test5.jpg" ) ) ;
IEnumerable < FileInfo > files = GetFilesByExtensions ( di , ".gif" ) ;
//IEnumerable<FileInfo> files = GetFilesByExtensions(di, ".gif", ".webp", ".bmp", ".jpg", ".png", ".tif");
foreach ( FileInfo fileInfo in files )
{
byte [ ] photoBytes = File . ReadAllBytes ( fileInfo . FullName ) ;
Console . WriteLine ( "Processing: " + fileInfo . Name ) ;
// foreach (FileInfo fileInfo in files)
// {
byte [ ] photoBytes = File . ReadAllBytes ( fileInfo . FullName ) ;
Console . WriteLine ( "Processing: " + fileInfo . Name ) ;
Stopwatch stopwatch = new Stopwatch ( ) ;
stopwatch . Start ( ) ;
Stopwatch stopwatch = new Stopwatch ( ) ;
stopwatch . Start ( ) ;
// ImageProcessor
using ( MemoryStream inStream = new MemoryStream ( photoBytes ) )
// ImageProcessor
using ( MemoryStream inStream = new MemoryStream ( photoBytes ) )
{
using ( ImageFactory imageFactory = new ImageFactory ( true ) )
{
using ( ImageFactory imageFactory = new ImageFactory ( true ) )
{
Size size = new Size ( 8 4 4 , 1 0 1 7 ) ;
ResizeLayer layer = new ResizeLayer ( size , ResizeMode . Max , AnchorPosition . Center , false ) ;
//ContentAwareResizeLayer layer = new ContentAwareResizeLayer(size)
//{
// ConvolutionType = ConvolutionType.Sobel
//};
// Load, resize, set the format and quality and save an image.
imageFactory . Load ( inStream )
//.Overlay(new ImageLayer
// {
// Image = overlay,
// Opacity = 50
// })
//.Alpha(50)
//.BackgroundColor(Color.White)
//.Resize(new Size((int)(size.Width * 1.1), 0))
//.ContentAwareResize(layer)
//.Constrain(size)
//.Mask(mask)
//.Format(new PngFormat())
//.BackgroundColor(Color.Cyan)
//.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))
//.DetectEdges(new SobelEdgeFilter(), true)
//.DetectEdges(new LaplacianOfGaussianEdgeFilter())
//.EntropyCrop()
//.Filter(MatrixFilters.Invert)
//.Contrast(50)
//.Filter(MatrixFilters.Comic)
//.Flip()
//.Filter(MatrixFilters.HiSatch)
. Pixelate ( 8 )
. Rotate ( 4 5 )
//.GaussianSharpen(10)
//.Format(new PngFormat() { IsIndexed = true })
//.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 ( ) ;
}
Size size = new Size ( 8 4 4 , 1 0 1 7 ) ;
ResizeLayer layer = new ResizeLayer ( size , ResizeMode . Max , AnchorPosition . Center , false ) ;
//ContentAwareResizeLayer layer = new ContentAwareResizeLayer(size)
//{
// ConvolutionType = ConvolutionType.Sobel
//};
// Load, resize, set the format and quality and save an image.
imageFactory . Load ( inStream )
//.Overlay(new ImageLayer
// {
// Image = overlay,
// Opacity = 50
// })
//.Alpha(50)
//.BackgroundColor(Color.White)
//.Resize(new Size((int)(size.Width * 1.1), 0))
//.ContentAwareResize(layer)
//.Constrain(size)
//.Mask(mask)
//.Format(new PngFormat())
//.BackgroundColor(Color.Cyan)
//.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))
//.DetectEdges(new SobelEdgeFilter(), true)
//.DetectEdges(new LaplacianOfGaussianEdgeFilter())
//.EntropyCrop()
//.Filter(MatrixFilters.Invert)
//.Contrast(50)
//.Filter(MatrixFilters.Comic)
//.Flip()
//.Filter(MatrixFilters.HiSatch)
//.Pixelate(8)
//.Rotate(45)
//.GaussianSharpen(10)
//.Format(new PngFormat() { IsIndexed = true })
//.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 ( ) ;
}
}
Console . WriteLine ( @"Completed {0} in {1:s\.fff} secs with peak memory usage of {2}." , fileInfo . Name , stopwatch . Elapsed , Process . GetCurrentProcess ( ) . PeakWorkingSet64 . ToString ( "#,#" ) ) ;
long peakWorkingSet64 = Process . GetCurrentProcess ( ) . PeakWorkingSet64 ;
float mB = peakWorkingSet64 / ( float ) 1 0 2 4 / 1 0 2 4 ;
//Console.WriteLine("Processed: " + fileInfo.Name + " in " + stopwatch.ElapsedMilliseconds + "ms");
}
Console . WriteLine ( @"Completed {0} in {1:s\.fff} secs {2}Peak memory usage was {3} bytes or {4} Mb." , fileInfo . Name , stopwatch . Elapsed , Environment . NewLine , peakWorkingSet64 . ToString ( "#,#" ) , mB ) ;
//Console.WriteLine("Processed: " + fileInfo.Name + " in " + stopwatch.ElapsedMilliseconds + "ms");
//}
Console . ReadLine ( ) ;
}