public delegate bool ImageOptimizerDirectory(
ImageOptimizerDirectoryData data
)
data
A ImageOptimizerDirectoryData object containing information about the image(s) being optimized.
A System.Boolean value that indicates whether to cancel the optimization operation for the current image. Possible values are:
Value | Description |
---|---|
false | Cancel the optimization operation for the current image. |
true | Continue normally. |
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.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageOptimization;
int _imageNo;
public void TestDirImageOptimizer()
{
_imageNo = 0;
// Initialize the RasterCodecs class
RasterCodecs codecs = new RasterCodecs();
// The input and output directories
string inputDirectory = LEAD_VARS.ImagesDir;
string outputDirectory = Path.Combine(LEAD_VARS.ImagesDir, "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.
}
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;
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";
}