L_BrowseDir

#include "l_bitmap.h"

L_LTTMB_API L_INT L_BrowseDir(pszPath, pszFilter, pThumbOptions, bStopOnError, bIncludeSubDirs, bExpandMultipage, lSizeDisk, lSizeMem, pfnBrowseDirCB, pUserData)

Browses the specified directory for supported images, and generates thumbnails for each image file that is found.

Parameters

L_TCHAR *pszPath

Character string containing the name of the directory to browse for images

L_TCHAR *pszFilter

Character string containing the file filter to use for browsing. Ex. *.jpg

pTHUMBOPTIONS pThumbOptions

Pointer to a structure containing the thumbnail creation options for the browser.

L_BOOL bStopOnError

Flag that indicates whether or not to stop generating thumbnails when an error occurs. Possible values are:

Value Meaning
TRUE Stop generating thumbnails if an error occurs.
FALSE Do not stop generating thumbnails if an error occurs.

L_BOOL bIncludeSubDirs

Flag that indicates whether or not to recurse subdirectories when looking for files. Possible values are:

Value Meaning
TRUE Recurse subdirectories.
FALSE Do not recurse subdirectories.

L_BOOL bExpandMultipage

Flag that indicates whether or not to expand multipage files. If True, each page from a multipage file will be loaded. Possible values are:

Value Meaning
TRUE Expand multipage files, loading each page from a multipage file.
FALSE Do not expand multipage files.

L_SSIZE_T lSizeDisk

Maximum size of file to load. Use this to limit the size of images that the browse will attempt to load. Pass 0 for no limit.

L_SSIZE_T lSizeMem

Maximum size of image in memory to load. Use this to limit the size of images that the browse will attempt to load. Pass 0 for no limit.

BROWSEDIRCALLBACK pfnBrowseDirCB

Callback function required for handling each of the generated thumbnails. You must specify a callback in order to process the thumbnails.The callback function must adhere to the function prototype described in BROWSEDIRCALLBACK Function.

L_VOID* 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.

Returns

Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

Use this function to browse a directory for image files that LEADTOOLS supports. Each supported file that is found will be loaded, and a thumbnail will be generated for the image. In the callback function, you can process the thumbnail in any manner your application requires. For example, you can add the thumbnails to the LEADTOOLS ImageList Control.

If 0 is specified for either pThumbOptions->nHeight or pThumbOptions->nWidth, the image will not be resized. The whole image will be returned in the BROWSEDIRCALLBACK function.

If -1 is specified for either the pThumbOptions->nHeight or pThumbOptions->nWidth, the image will not be loaded at all. The BROWSEDIRCALLBACK function will be called for each file, but will only receive file information, not a valid image.

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

Example

This example will browse a folder and generate thumbnails for all supported images that are found.

L_INT EXT_CALLBACK BrowseDirCallback(pBITMAPHANDLE pBitmap,  
                        L_TCHAR* pszFilename,  
                        pFILEINFO pFileInfo,  
                        L_INT nStatusCode,  
                        L_INT nPercent,  
                        L_VOID* pUserData) 
{ 
   L_TCHAR buf[200]; 
   UNREFERENCED_PARAMETER(pUserData); 
   UNREFERENCED_PARAMETER(nPercent); 
   UNREFERENCED_PARAMETER(pFileInfo); 
   UNREFERENCED_PARAMETER(pBitmap); 
 
   switch(nStatusCode) 
   { 
   case BROWSE_PRELOAD:/* notify image is about to be loaded */ 
      return SUCCESS; 
   case BROWSE_LOADING:/* in the process of loading an image */ 
      return SUCCESS; 
   case SUCCESS:/* successful thumbnail generation */ 
      /* Do something with the thumbnail, i.e. insert into ImageList Control */ 
      /* ... */ 
      break; 
   case BROWSE_SKIPPED:/* skipped a large file */ 
      /* report error to user */ 
      wsprintf(buf, TEXT("Skipped File: %s !"), pszFilename); 
      MessageBox(NULL, buf, TEXT("Skipped"), MB_OK); 
      return SUCCESS; 
   default: 
      if(nStatusCode < SUCCESS) 
      { 
         /* report error to user */ 
         wsprintf(buf, TEXT("Error: %d - Generating Thumbnail!\n%s\nPress OK to Continue!"), nStatusCode, pszFilename); 
         if(MessageBox(NULL, buf, TEXT("Error"), MB_OKCANCEL|MB_ICONERROR) == IDCANCEL) 
            return(ERROR_USER_ABORT); 
      } 
   } 
 
   return SUCCESS; 
} 
 
L_INT BrowseDirExample(L_VOID) 
{ 
   L_INT nRet; 
   THUMBOPTIONS Opt; 
   memset(&Opt, 0, sizeof(THUMBOPTIONS)); 
   Opt.uStructSize = sizeof(THUMBOPTIONS); 
   Opt.nWidth = 115; /* thumbnail width                          */ 
   Opt.nHeight = 115; /* thumbnail height                          */ 
   Opt.nBits = 24; /* 24-bit                                   */ 
   Opt.uCRFlags = 0; /* ignored, b/c we specified 24-bit         */ 
   Opt.bMaintainAspect = TRUE; /* maintain aspect when creating thumbnails */ 
   Opt.bForceSize = FALSE; /* don't force size                         */ 
   Opt.crBackColor = RGB(0,0,0); /* background color is ignored              */ 
   Opt.bLoadStamp = TRUE; /* try to load stamp if present in file     */ 
   Opt.bResample = TRUE; /* resample, for better quality thumbnails  */ 
   nRet = L_BrowseDir( MAKE_IMAGE_PATH(L_TEXT("")), 
                       TEXT("*.jpg"), 
                       &Opt, 
                       FALSE, /* don't stop on error                      */ 
                       FALSE, /* do not recurse subdirectories            */ 
                       FALSE, /* do not expand multi-page files            */ 
                       0,     /* no limit on file size                    */ 
                       4000*1024,/* set limit on image size to 4MB        */ 
                       BrowseDirCallback,/* callback  */ 
                       NULL );/* no user data                             */ 
   return nRet; 
} 

Help Version 20.0.2020.4.3
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help