#include "l_bitmap.h"
L_LTIMGOPT_API L_INT L_OptOptimizeDir(pszOrgDirPath, pszOptDirPath, pOptImgOptions, pszFilesExt, bIncludeSubDirs, pfnOptImgDirCB, pUserData)
L_TCHAR * pszOrgDirPath; |
full path directory to optimize |
L_TCHAR * pszOptDirPath; |
full path directory to save optimized images |
pOPTIMIZEIMAGEOPTIONS pOptImgOptions; |
pointer to the OPTIMIZEIMAGEOPTIONS structure |
L_TCHAR * pszFilesExt; |
files extension(s) to optimize |
L_BOOL bIncludeSubDirs; |
flag that indicates whether to include sub-directories |
OPTIMIZEIMAGEDIRCALLBACK pfnOptImgDirCB; |
optional callback function |
L_VOID * pUserData; |
pointer to more parameters for the callback |
Optimizes a directory of images using the specified optimization options, and saves the optimized images to a new directory with the same hierarchy.
Parameter | Description | |
pszOrgDirPath | Character string that contains full path directory of supported images to optimize. | |
pszOptDirPath | Character string that contains full path directory to save the optimized image(s). | |
pOptImgOptions | Pointer to an OPTIMIZEIMAGEOPTIONS structure that contains the options used in optimization. Pass NULL to use the default optimization options. | |
pszFilesExt |
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 ".". |
|
bIncludeSubDirs | 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. | |
pfnOptImgDirCB |
Optional callback function for additional processing.
The callback function must adhere to the function prototype described in OPTIMIZEIMAGEDIRCALLBACK Function. |
|
pUserData |
Void pointer that you can use to pass one or more additional parameters that the callback function needs.
To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure. If the additional parameters are not needed, you can pass NULL in this parameter. |
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.
Required DLLs and Libraries
For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application. |
Win32, x64.
Functions: |
|
Topics: |
|
|
This Example is going to optimizes all files with extensions jpg, bmp and tmp
#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName
L_INT EXT_CALLBACK fnOptDirCB(pOPTIMIZEIMAGEDIRINFO pImgDirInfo,
L_VOID * pUserData)
{
UNREFERENCED_PARAMETER(pUserData);
// Check if pCBData is a vlid pointer
if(pImgDirInfo)
{
L_TCHAR buf[200]; // Message buffer
switch(pImgDirInfo->nStatusCode)
{
case SUCCESS: /* Optimizing operation Successfully done */
{
MessageBox(NULL, TEXT("Operation Successfully Done"), TEXT("Optimizing"), MB_OK);
}
break;
case OPTIMIZE_DIR_PRE_OPTIMIZINGIMAGE: /* Pre Optimizing Image */
{
MessageBox(NULL, TEXT("Pre Optimize Image"), TEXT("Note"), MB_OK);
if((pImgDirInfo->pFileInfo->Format == FILE_JPEG) ||
(pImgDirInfo->pFileInfo->Format == FILE_JPEG_411) ||
(pImgDirInfo->pFileInfo->Format == FILE_JPEG_422) ||
(pImgDirInfo->pFileInfo->Format == FILE_EXIF_JPEG_411) ||
(pImgDirInfo->pFileInfo->Format == FILE_EXIF_JPEG_422))
pImgDirInfo->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"), pImgDirInfo->nFilePercent, pImgDirInfo->szOrgFileName, pImgDirInfo->szOptFileName, i, pImgDirInfo->nTotalFolderFilesCount);
MessageBox(NULL, buf, TEXT("Optimizing"), MB_OK);
// if nFilePercent = 100 increment the counter by 1
if((pImgDirInfo->nFilePercent == 100) && ((i + 1) <= pImgDirInfo->nTotalFolderFilesCount))
i++;
}
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!"), pImgDirInfo->nStatusCode, pImgDirInfo->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 OptOptimizeDirExample(pOPTIMIZEIMAGEOPTIONS pOptImgOptions,
L_BOOL bIncludeSubDir,
L_VOID * pUserData)
{
return L_OptOptimizeDir(MAKE_IMAGE_PATH(TEXT("")), /* The original Dir to be optimized. */
MAKE_IMAGE_PATH(TEXT("OptimizedImages")),/* The New Dir to save the Optimized image(s) to.*/
pOptImgOptions, /* Optimization options.*/
TEXT("*.jpg;*.bmp"), /* optimize all images with ext jpg, bmp and tmp only.*/
bIncludeSubDir, /* Optimize or not the sub-dirs.*/
fnOptDirCB, /* Callback */
pUserData); /* User data */
}
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