Leadtools.ImageOptimization Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.8.31
ImageOptimizerDirectory Delegate
See Also  Example
Leadtools.ImageOptimization Namespace : ImageOptimizerDirectory Delegate




data
A ImageOptimizerDirectoryData object containing information about the image(s) being optimized.
Called during the directory optimization operation to give the user information about the image(s) being optimized.

Syntax

Visual Basic (Declaration) 
Public Delegate Function ImageOptimizerDirectory( _
   ByVal data As ImageOptimizerDirectoryData _
) As Boolean
Visual Basic (Usage)Copy Code
Dim instance As New ImageOptimizerDirectory(AddressOf HandlerMethod)
C# 
public delegate bool ImageOptimizerDirectory( 
   ImageOptimizerDirectoryData data
)
Managed Extensions for C++ 
public: __gc __delegate bool ImageOptimizerDirectory( 
   ImageOptimizerDirectoryData* data
)
C++/CLI 
public delegate bool ImageOptimizerDirectory( 
   ImageOptimizerDirectoryData^ data
)

Parameters

data
A ImageOptimizerDirectoryData object containing information about the image(s) being optimized.

Example

This example will optimize all Jpg files found in a specific directory, and save them into a separate folder

Visual BasicCopy Code
Private _imageNo As Integer

Public Sub TestDirImageOptimizer()
   _imageNo = 0

   ' Initialize the RasterCodecs class
   RasterCodecs.Startup()
   Dim codecs As RasterCodecs = New RasterCodecs()

   ' The input and output directories
   Dim inputDirectory As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images"
   Dim outputDirectory As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\OptimizedImages"

   ' Initialize a new Optimizer object
   Dim optimizer As ImageOptimizer = New ImageOptimizer()

   ' Optimization Options
   Dim options As ImageOptimizerOptions = ImageOptimizerOptions.Default

   optimizer.OptimizeDirectory(codecs, _
      inputDirectory, _
      outputDirectory, _
      options, _
      "*.jpg", _
      False, _
      AddressOf ImageOptimizerDirectory)

   'shutdown the RasterCodecs class.
   RasterCodecs.Shutdown()
End Sub

Public Function ImageOptimizerDirectory(ByVal data As ImageOptimizerDirectoryData) As Boolean
   Console.WriteLine(String.Format("File Percent = {0}%, Total Percent = {1}%", data.FilePercent, data.TotalPercent))

   If (_imageNo = data.TotalFolderFilesCount) Then

      ' Operation Done.
      Console.WriteLine("Optimization Operation Completed Successfully")
      Return True

   ElseIf (data.Status = ImageOptimizerDirectoryStatus.PreOptimizingImage) Then
      Dim text As String = String.Format("Optimizing Image {0} ?\n", data.InputFileName)
      Dim result As DialogResult = MessageBox.Show(text, "", MessageBoxButtons.YesNoCancel)

      If (result = DialogResult.Yes) Then
         ' Optimize the image using the default options.
         data.Options = ImageOptimizerOptions.Default
         Return True
      ElseIf (result = DialogResult.No) Then
         ' Skip this image.
         _imageNo += 1
         data.SkipImage = True
      Else
         ' Stop the whole operation.
         Return False
      End If
   ElseIf (data.FilePercent = 100) Then
      _imageNo += 1

      ' Displaying information about the optimized image.
      Dim msg As String = String.Format("Optimizing File ( {0} of {1} ) \n" + _
         "--------------------------------\n" + _
         "Source File Name = {2}\n" + _
         "Detination File Name = {3}\n" + _
         "No of Pages = {4}\n", _
         _imageNo, data.TotalFolderFilesCount, data.InputFileName, data.OutputFileName, data.ImageInfo.TotalPages)

      Console.WriteLine(msg)
   End If
   Return True
End Function
C#Copy Code
int _imageNo; 
 
public void TestDirImageOptimizer( ) 

   _imageNo = 0; 
 
   // Initialize the RasterCodecs class 
   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // The input and output directories 
   string inputDirectory = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images"; 
   string outputDirectory = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\OptimizedImages"; 
 
   // Initialize a new Optimizer object 
   ImageOptimizer optimizer = new ImageOptimizer(); 
 
   // Optimization Options 
   ImageOptimizerOptions options = ImageOptimizerOptions.Default; 
 
   optimizer.OptimizeDirectory(codecs, 
      inputDirectory, 
      outputDirectory, 
      options, 
      "*.jpg", 
      false, 
      ImageOptimizerDirectory); 
 
   //shutdown the RasterCodecs class. 
   RasterCodecs.Shutdown(); 

 
bool ImageOptimizerDirectory(ImageOptimizerDirectoryData data) 

   Console.WriteLine(string.Format("File Percent = {0}%,    Total Percent = {1}%", data.FilePercent, data.TotalPercent)); 
 
   if(_imageNo == data.TotalFolderFilesCount) 
   { 
      // Operation Done. 
      Console.WriteLine("Optimization Operation Completed Successfully"); 
      return true; 
   } 
   else if(data.Status == ImageOptimizerDirectoryStatus.PreOptimizingImage) 
   { 
      string text = string.Format("Optimizing Image {0} ?\n", data.InputFileName); 
      DialogResult result = MessageBox.Show(text, "", MessageBoxButtons.YesNoCancel); 
 
      if(result == DialogResult.Yes) 
      { 
         // Optimize the image using the default options. 
         data.Options = ImageOptimizerOptions.Default; 
         return true; 
      } 
      else if(result == DialogResult.No) 
      { 
         // Skip this image. 
         _imageNo++; 
         data.SkipImage = true; 
      } 
      else 
         // Stop the whole operation. 
         return false; 
   } 
   else if(data.FilePercent == 100) 
   { 
      _imageNo++; 
 
      // Displaying information about the optimized image. 
      string msg = string.Format("Optimizing File ( {0} of {1} ) \n" + 
         "--------------------------------\n" + 
         "Source File Name = {2}\n" + 
         "Detination File Name = {3}\n" + 
         "No of Pages = {4}\n", 
         _imageNo, data.TotalFolderFilesCount, data.InputFileName, data.OutputFileName, data.ImageInfo.TotalPages); 
 
      Console.WriteLine(msg); 
   } 
   return true; 
}

Remarks

This method will be called to provide the user information about the image(s) being optimized, such as the percent completion for the current image being optimized, and the percent completion for all files being optimized.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also