Batch processes a collection of RasterCommand object on a collection of RasterImage objects.
public class RasterCommandProcessor Public Class RasterCommandProcessor public ref class RasterCommandProcessor Use the RasterCommandProcessor class to perform "batch" image processing, where one or more commands are executed on one or more images.
This example will load multiple images from disk and executes multiple image processing commands on them before saving the result into a single multi-page tif file.
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing;using LeadtoolsExamples.Common;public void RasterCommandProcessorExample(){RasterCodecs codecs = new RasterCodecs();string destFileName = Path.Combine(ImagesPath.Path, "RasterCommandProcessor.tif");// create a raster command processorRasterCommandProcessor processor = new RasterCommandProcessor();// add the commands (color-res to 8 then flip)processor.Commands.Add(new ColorResolutionCommand(ColorResolutionCommandMode.InPlace,8,RasterByteOrder.Rgb,RasterDitheringMethod.None,ColorResolutionCommandPaletteFlags.Optimized,null));processor.Commands.Add(new FlipCommand(false));// load the imagesconst int imageCount = 4;for (int i = 0; i < imageCount; i++){string srcFileName = Path.Combine(ImagesPath.Path, string.Format("Image{0}.cmp", (i + 1) % 2 + 1));processor.Images.Add(codecs.Load(srcFileName));}// run the commandsprocessor.Progress += new EventHandler<RasterCommandProcessorProgressEventArgs>(processor_Progress);processor.Run();processor.Progress -= new EventHandler<RasterCommandProcessorProgressEventArgs>(processor_Progress);// save the result image as multi-page tif fileif (File.Exists(destFileName))File.Delete(destFileName);for (int i = 0; i < imageCount; i++)codecs.Save(processor.Images[i],destFileName,RasterImageFormat.Tif,8,1,1,-1,CodecsSavePageMode.Append);// clean upfor (int i = 0; i < imageCount; i++)processor.Images[i].Dispose();}void processor_Progress(object sender, RasterCommandProcessorProgressEventArgs e){// show information about the commandConsole.Write("Running command {0} ({1}) of {2}, ", e.CommandNumber, e.Command, e.TotalCommands);Console.Write("On image {0} ({1} by {2} pixels) of {3}, ", e.ImageNumber, e.Image.Width, e.Image.Height, e.TotalImages);Console.WriteLine("{0}% done", e.Percent);}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessingPublic Sub RasterCommandProcessorExample()Dim codecs As RasterCodecs = New RasterCodecs()Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "RasterCommandProcessor.tif")' create a raster command processorDim processor As RasterCommandProcessor = New RasterCommandProcessor()' add the commands (color-res to 8 then flip)processor.Commands.Add(New ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 8, RasterByteOrder.Rgb, RasterDitheringMethod.None,ColorResolutionCommandPaletteFlags.Optimized, Nothing))processor.Commands.Add(New FlipCommand(False))' load the imagesConst imageCount As Integer = 2For i As Integer = 0 To imageCount - 1Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, String.Format("Image{0}.cmp", i + 1))processor.Images.Add(codecs.Load(srcFileName))Next i' run the commandsAddHandler processor.Progress, AddressOf processor_Progressprocessor.Run()RemoveHandler processor.Progress, AddressOf processor_Progress' save the result image as multi-page tif fileIf File.Exists(destFileName) ThenFile.Delete(destFileName)End IfFor i As Integer = 0 To imageCount - 1codecs.Save(processor.Images(i), destFileName, RasterImageFormat.Tif, 8, 1, 1, -1, CodecsSavePageMode.Append)Next i' clean upFor i As Integer = 0 To imageCount - 1processor.Images(i).Dispose()Next iEnd SubPrivate Sub processor_Progress(ByVal sender As Object, ByVal e As RasterCommandProcessorProgressEventArgs)' show information about the commandConsole.Write("Running command {0} ({1}) of {2}, ", e.CommandNumber, e.Command, e.TotalCommands)Console.Write("On image {0} ({1} by {2} pixels) of {3}, ", e.ImageNumber, e.Image.Width, e.Image.Height, e.TotalImages)Console.WriteLine("{0}% done", e.Percent)End SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
using Leadtools;using Leadtools.Codecs;using Leadtools.Examples;using Leadtools.ImageProcessing;using Leadtools.Windows.Media;public void RasterCommandProcessorExample(RasterImage image1, RasterImage image2, RasterImage image3, Stream destStream){RasterCodecs codecs = new RasterCodecs();// create a raster command processorRasterCommandProcessor processor = new RasterCommandProcessor();// add the commands (color-res to 8 then flip)processor.Commands.Add(new ColorResolutionCommand(ColorResolutionCommandMode.InPlace,8,RasterByteOrder.Rgb,RasterDitheringMethod.None,ColorResolutionCommandPaletteFlags.Optimized,null));processor.Commands.Add(new FlipCommand(false));// add the imagesprocessor.Images.Add(image1);processor.Images.Add(image2);processor.Images.Add(image3);// run the commandsprocessor.Progress += new EventHandler<RasterCommandProcessorProgressEventArgs>(processor_Progress);processor.Run();processor.Progress -= new EventHandler<RasterCommandProcessorProgressEventArgs>(processor_Progress);// save the result image as multi-page tif filefor (int i = 0; i < 3; i++)codecs.Save(processor.Images[i],destStream,RasterImageFormat.Tif,8,1,1,-1,CodecsSavePageMode.Append);// clean upfor (int i = 0; i < 3; i++)processor.Images[i].Dispose();}void processor_Progress(object sender, RasterCommandProcessorProgressEventArgs e){// show information about the commandConsole.Write("Running command {0} ({1}) of {2}, ", e.CommandNumber, e.Command, e.TotalCommands);Console.Write("On image {0} ({1} by {2} pixels) of {3}, ", e.ImageNumber, e.Image.Width, e.Image.Height, e.TotalImages);Debug.WriteLine("{0}% done", e.Percent);}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessingImports Leadtools.Windows.MediaPublic Sub RasterCommandProcessorExample(ByVal image1 As RasterImage, ByVal image2 As RasterImage, ByVal image3 As RasterImage, ByVal destStream As Stream)Dim codecs As RasterCodecs = New RasterCodecs()' create a raster command processorDim processor As RasterCommandProcessor = New RasterCommandProcessor()' add the commands (color-res to 8 then flip)processor.Commands.Add(New ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 8, RasterByteOrder.Rgb, RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Optimized, Nothing))processor.Commands.Add(New FlipCommand(False))' add the imagesprocessor.Images.Add(image1)processor.Images.Add(image2)processor.Images.Add(image3)' run the commandsAddHandler processor.Progress, AddressOf processor_Progressprocessor.Run()RemoveHandler processor.Progress, AddressOf processor_Progress' save the result image as multi-page tif fileFor i As Integer = 0 To 2codecs.Save(processor.Images(i), destStream, RasterImageFormat.Tif, 8, 1, 1, -1, CodecsSavePageMode.Append)Next i' clean upFor i As Integer = 0 To 2processor.Images(i).Dispose()Next iEnd SubPrivate Sub processor_Progress(ByVal sender As Object, ByVal e As RasterCommandProcessorProgressEventArgs)' show information about the commandConsole.Write("Running command {0} ({1}) of {2}, ", e.CommandNumber, e.Command, e.TotalCommands)Console.Write("On image {0} ({1} by {2} pixels) of {3}, ", e.ImageNumber, e.Image.Width, e.Image.Height, e.TotalImages)Debug.WriteLine("{0}% done", e.Percent)End Sub
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
