Leadtools Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
RasterCommandProcessor Class
See Also  Members   Example 
Leadtools.ImageProcessing Namespace : RasterCommandProcessor Class



Batch processes a collection of RasterCommand object on a collection of RasterImage objects.

Object Model



Syntax

Visual Basic (Declaration) 
Public Class RasterCommandProcessor 
Visual Basic (Usage)Copy Code
Dim instance As RasterCommandProcessor
C# 
public class RasterCommandProcessor 
C++/CLI 
public ref class RasterCommandProcessor 

Example

This example will load multiple images from disk and executes multiple image proecessing commands on them before saving the result into a single multi-page tif file.

Visual BasicCopy Code
Public Sub RasterCommandProcessorExample()
 RasterCodecs.Startup()
 Dim codecs As RasterCodecs = New RasterCodecs()

 Dim srcFileDir As String = LeadtoolsExamples.Common.ImagesPath.Path
 Dim destFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "RasterCommandProcessor.tif"

 ' create a raster command processor
 Dim 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 images
 Const imageCount As Integer = 4
 For i As Integer = 0 To imageCount - 1
    Dim srcFileName As String = Path.Combine(srcFileDir, String.Format("Image{0}.cmp", i + 1))
    processor.Images.Add(codecs.Load(srcFileName))
 Next i

 ' run the commands
 AddHandler processor.Progress, AddressOf processor_Progress
 processor.Run()
 RemoveHandler processor.Progress, AddressOf processor_Progress

 ' save the result image as multi-page tif file
 If File.Exists(destFileName) Then
    File.Delete(destFileName)
 End If

 For i As Integer = 0 To imageCount - 1
    codecs.Save(processor.Images(i), destFileName, RasterImageFormat.Tif, 8, 1, 1, -1, CodecsSavePageMode.Append)
 Next i

 ' clean up
 For i As Integer = 0 To imageCount - 1
    processor.Images(i).Dispose()
 Next i

 RasterCodecs.Shutdown()
      End Sub

      Private Sub processor_Progress(ByVal sender As Object, ByVal e As RasterCommandProcessorProgressEventArgs)
 ' show information about the command
 Console.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 Sub
C#Copy Code
public void RasterCommandProcessorExample() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileDir = LeadtoolsExamples.Common.ImagesPath.Path; 
   string destFileName = LeadtoolsExamples.Common.ImagesPath.Path + "RasterCommandProcessor.tif"; 
 
   // create a raster command processor 
   RasterCommandProcessor 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 images 
   const int imageCount = 4; 
   for(int i = 0; i < imageCount; i++) 
   { 
      string srcFileName = Path.Combine(srcFileDir, string.Format("Image{0}.cmp", i + 1)); 
      processor.Images.Add(codecs.Load(srcFileName)); 
   } 
 
   // run the commands 
   processor.Progress += new EventHandler<RasterCommandProcessorProgressEventArgs>(processor_Progress); 
   processor.Run(); 
   processor.Progress -= new EventHandler<RasterCommandProcessorProgressEventArgs>(processor_Progress); 
 
   // save the result image as multi-page tif file 
   if(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 up 
   for(int i = 0; i < imageCount; i++) 
      processor.Images[i].Dispose(); 
 
   RasterCodecs.Shutdown(); 

 
void processor_Progress(object sender, RasterCommandProcessorProgressEventArgs e) 

   // show information about the command 
   Console.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); 
}

Remarks

Use the RasterCommandProcessor class to perform "batch" image processing, where one or more commands are executed on one or more images.

Inheritance Hierarchy

System.Object
   Leadtools.ImageProcessing.RasterCommandProcessor

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also