Browses the specified directory for supported images, and generates thumbnails for each image file that is found.
#include "ltwrappr.h"
virtual L_INT LFile::BrowseDir(pszPath, pszFilter, pThumbOptions, bStopOnError=FALSE, bIncludeSubDirs=FALSE, bExpandMultipage=FALSE, lSizeDisk=0, lSizeMem=0)
Character string containing the name of the directory to browse for images
Character string containing the file filter to use for browsing. Ex. *.jpg
Pointer to a structure containing the thumbnail creation options for the browser.
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. |
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. |
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. |
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.
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.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
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 LFile::BrowseDirCallBack function.
If -1 is specified for either the pThumbOptions->nHeight or pThumbOptions->nWidth, the image will not be loaded at all. The LFile::BrowseDirCallBack function will be called for each file, but will only receive file information, not a valid image.
Win32, x64.
// define user LFile class to override CallBack
class LMyBrowse : public LFile
{
public:
HDC m_hDC;
public:
LMyBrowse();
virtual ~LMyBrowse();
virtual L_INT BrowseDirCallBack( LBitmapBase * pLBitmap,
L_TCHAR * pszFilename,
pFILEINFO pFileInfo,
L_INT nStatus,
L_INT nPercent
);
};
LMyBrowse::LMyBrowse()
{
m_hDC = NULL;
}
LMyBrowse::~LMyBrowse()
{
}
L_INT LMyBrowse::BrowseDirCallBack(LBitmapBase * pLBitmap,
L_TCHAR * pszFilename,
pFILEINFO pFileInfo,
L_INT nStatus, L_INT nPercent)
{
UNREFERENCED_PARAMETER(pszFilename);
UNREFERENCED_PARAMETER(pFileInfo);
UNREFERENCED_PARAMETER(nPercent);
// we have a thumbnail, do something with it
if(nStatus == SUCCESS)
{
pLBitmap->Paint()->SetDC(m_hDC);
pLBitmap->Paint()->PaintDC();
}
else if(nStatus == BROWSE_LOADING)
{
// imaging being loaded
}
return SUCCESS ;
}
// Test Function
L_INT LFile__BrowseDirExample(HDC hDC)
{
L_INT nRet;
LBase::LoadLibraries(LT_ALL_LEADLIB);
LMyBrowse myBrowse;
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 */
myBrowse.m_hDC = hDC;
nRet = myBrowse.BrowseDir(MAKE_IMAGE_PATH(TEXT("")), // path
TEXT("*.*"), // all files
&Opt,
FALSE, // do not stop on errors
FALSE, // do not include sub-dirs
FALSE, // do not expand multipage files
0, // no limit to file sizes
4000*1024); // limit image in memory to 4MB
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