Optimizes a directory of images using the specified optimization options, and saves the optimized images to a new directory with the same hierarchy.
#include "ltwrappr.h"
L_INT LOptimize::OptimizeDir(pszOrgDirPath, pszOptDirPath, pOptImgOptions, pszFilesExt, bIncludeSubDirs)
Character string that contains the full path directory of the supported images to optimize.
Character string that contains the full path directory to save the optimized image(s).
Pointer to an OPTIMIZEIMAGEOPTIONS structure that contains the options used in optimization. Pass NULL to use the default optimization options.
Pointer to a character string that contains the extensions of the files to optimize. This is a NULL terminated string and can have a maximum length of MAX_PATH. For example:
To optimize all "gif" and "jpeg" files, pszFilesExt should be set to ".gif;.jpeg".
To optimize all the supported files found in the pszOrgDirPath directory, regardless of the their extensions, pszFilesExt should be set to ".".
Flag that indicates whether to include sub-directories when optimizing. Possible values are:
Value | Meaning |
---|---|
TRUE | Include sub-directories when optimizing. |
FALSE | Exclude sub-directories when optimizing. |
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
This function looks for all the selected and supported files in the pszOrgDirPath directory and optimizes them using the optimization options passed in the pOptImgOptions parameter. It then saves the optimized images to the pszOptDirPath directory.
Both the pszOrgDirPath and pszOptDirPath parameters should contain a full path, complete with drive name. The pszOrgDirPath parameter should contain the full path to the input (original) directory, and the pszOptDirPath parameter should contain the full path to the output (optimized) directory.
This function does not support 32-bit grayscale images. It returns the error code ERROR_GRAY32_UNSUPPORTED if a 32-bit grayscale image is passed to this function.
Win32, x64.
class LOptimizeDirChild : public LOptimize
{
public:
LOptimizeDirChild();
~LOptimizeDirChild();
virtual L_INT OptimizeDirCallBack(pOPTIMIZEIMAGEDIRINFO pOptImgDirCBInfo);
};
LOptimizeDirChild::LOptimizeDirChild()
{
}
LOptimizeDirChild::~LOptimizeDirChild()
{
}
L_INT LOptimizeDirChild::OptimizeDirCallBack(pOPTIMIZEIMAGEDIRINFO pOptImgDirCBInfo)
{
// Check if pOPTIMIZEIMAGEDIRINFO data is a valid pointer
if(pOptImgDirCBInfo)
{
L_TCHAR buf[200]; // Message buffer
switch(pOptImgDirCBInfo->nStatusCode)
{
case OPTIMIZE_DIR_PRE_OPTIMIZINGIMAGE: /* Pre Optimizing Image */
{
MessageBox(NULL, TEXT("Pre Optimize Image"), TEXT("Note"), MB_OK);
if((pOptImgDirCBInfo->pFileInfo->Format == FILE_JPEG) ||
(pOptImgDirCBInfo->pFileInfo->Format == FILE_JPEG_411) ||
(pOptImgDirCBInfo->pFileInfo->Format == FILE_JPEG_422) ||
(pOptImgDirCBInfo->pFileInfo->Format == FILE_EXIF_JPEG_411) ||
(pOptImgDirCBInfo->pFileInfo->Format == FILE_EXIF_JPEG_422))
pOptImgDirCBInfo->pOptImgOptions->JPEGColorSpace = JPEG_COLORSPACE_422;
}
break;
case OPTIMIZE_DIR_OPTIMIZINGIMAGE: /* Optimizing ... */
{
static int i = 1; // Optimized files counter
// display the current file and total percent
wsprintf(buf, TEXT("%d %% of optimizing %s to %s \nFiles %d of %d"), pOptImgDirCBInfo->nFilePercent, pOptImgDirCBInfo->szOrgFileName, pOptImgDirCBInfo->szOptFileName, i, pOptImgDirCBInfo->nTotalFolderFilesCount);
MessageBox(NULL, buf, TEXT("Optimizing"), MB_OK);
// if nFilePercent = 100 increment the counter by 1
if((pOptImgDirCBInfo->nFilePercent == 100) && ((i + 1) <= pOptImgDirCBInfo->nTotalFolderFilesCount))
i++;
}
break;
case SUCCESS: /* Optimizing operation Successfully done */
{
MessageBox(NULL, TEXT("Operation Successfully Done"), TEXT("Optimizing"), MB_OK);
}
break;
default:
{
/* report error to user */
/* Give the user the ability to skip the current image only or cancel the whole operation*/
wsprintf(buf, TEXT("Error: %d - Optimizing Image!\n%s\nPress OK to skip this file and optimize the next one!"), pOptImgDirCBInfo->nStatusCode, pOptImgDirCBInfo->szOrgFileName);
if(MessageBox(NULL, buf, TEXT("Error"), MB_OKCANCEL|MB_ICONERROR) == IDOK)
return(ERROR_OPT_SKIPIMAGE);
else
return(ERROR_OPT_ABORT);
}
break;
}
}
return SUCCESS;
}
L_INT LOptimize__OptimizeDirExample(L_TCHAR* pszPath)
{
L_INT nRet ;
LOptimizeDirChild opt ;
opt.EnableCallBack(TRUE) ;
OPTIMIZEIMAGEOPTIONS OptImgOptions;
OptImgOptions.uStructSize = sizeof(OptImgOptions);
OptImgOptions.uJPEGQFactor = 35;
OptImgOptions.uPNGQFactor=5;
OptImgOptions.JPEGColorSpace = JPEG_COLORSPACE_422;
OptImgOptions.nPercent=50;
OptImgOptions.uDistance=0;
OptImgOptions.bPickSamePalette=L_TRUE;
nRet = opt.OptimizeDir( pszPath, /* The original Dir to be optimized. */
MAKE_IMAGE_PATH(TEXT("OptimizedImages")),/* The New Dir to save the Optimized image(s) to.*/
&OptImgOptions, /* Optimization options.*/
TEXT("*.jpg;*.bmp;*.gif"), /* optimize all images with ext jpg, gif and bmp only.*/
TRUE /* Optimize or not the sub-dirs.*/);
if(nRet != SUCCESS)
return nRet;
return SUCCESS;
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document