L_CreateThumbnailFromFile

#include "l_bitmap.h"

L_LTFIL_API L_INT L_CreateThumbnailFromFile(pszFile, pBitmap, uStructSize, pThumbOptions, pfnCallback, pUserData, pLoadOptions, pFileInfo)

L_TCHAR* pszFile;

/* name of the image file to load */

pBITMAPHANDLE pBitmap;

/* pointer to the target bitmap handle */

L_UINT uStructSize;

/* size in bytes, of the structure pointed to by pBitmap */

pTHUMBOPTIONS pThumbOptions;

/* pointer to a structure */

FILEREADCALLBACK pfnCallback;

/* optional callback function */

L_VOID* pUserData;

/* pointer to more parameters for the callback */

pLOADFILEOPTION pLoadOptions;

/* pointer to optional extended load options */

pFILEINFO pFileInfo;

/* pointer to a structure */

Creates a thumbnail from the specified image file.

Parameter

Description

pszFile

Character string containing the name of the file to load.

pBitmap

Pointer to the bitmap handle for the loaded data.

uStructSize

Size in bytes, of the structure pointed to by pBitmap, for versioning. Use sizeof(BITMAPHANDLE).

pThumbOptions

Pointer to a structure containing thumbnail generation options. Pass NULL to get the default options.

pfnCallback

Optional callback function for additional processing.

 

If you do not provide a callback function, use NULL as the value of this parameter.

 

If you do provide a callback function, use the function pointer as the value of this parameter.

 

The callback function must adhere to the function prototype described in FILEREADCALLBACK 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.

pLoadOptions

Pointer to optional extended load options. Pass NULL to use the default load options.

pFileInfo

Pointer to a FILEINFO structure. This structure may contain file information used in loading an image, or it may be updated with information about the file being loaded.

 

If nothing is known about the file, pass NULL for this parameter, or declare a variable of type FILEINFO and set the FILEINFO. Flags to 0, then pass the address of the FILEINFO structure in this parameter. In this case, if the address of a FILEINFO structure is passed, the FILEINFO structure will be updated with the results of L_FileInfo.

 

If only the file type is known, set pFileInfo.Format to the file type and set pFileInfo.Flags to FILEINFO_FORMATVALID. This can also be done if L_FileInfo has been called previously, but values that affect the size of the image loaded have been changed (for example, by calling L_SetPCDResolution or L_SetWMFResolution). In this case the FILEINFO structure pointed to by pFileInfo will be updated with the results of L_FileInfo.

 

If L_FileInfo has been called prior to calling this function, and no changes have been made to the contents of the structure filled by L_FileInfo, then the address of the filled FILEINFO structure can be passed for this parameter. In this case, the FILEINFO.Flags member should be set to FILEINFO_INFOVALID. The L_FileInfo function will set the FILEINFO.Flags to FILEINFO_INFOVALID. In this case the load will be faster since this function does not have to query the file filters for the file type.

 

Note: Local variables are not initialized (since they are placed on the stack). So if you have a FILEINFO structure as a local variable, the value of its Flags parameter is undefined, possibly having FILEINFO_INFOVALID or FILEINFO_FORMATVALID set. That is why it is important to initialize FILEINFO.Flags before passing the address of the FILEINFO structure to the function.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function is used internally by L_BrowseDir to create/load the thumbnails for each file that is enumerated. You can use this function to manually create the thumbnail for a specified image file.

Since the function allocates storage to hold the image, it is up to you to free this storage by calling L_FreeBitmap.

The default thumbnail options are:

DefThumbOpt.nWidth

= 80;

DefThumbOpt.nHeight

= 80;

DefThumbOpt.nBits

= 0;

DefThumbOpt.uCRFlags

= 0;

DefThumbOpt.bMaintainAspect

= TRUE;

DefThumbOpt.bForceSize

= FALSE;

DefThumbOpt.crBackColor

= RGB(0,0,0);

DefThumbOpt.bLoadStamp

= TRUE;

DefThumbOpt.bResample

= FALSE;

Note: More options are available in the LOADFILEOPTION structure.

Required DLLs and Libraries

LTFIL

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Win32, x64, Mobile.

See Also

Functions:

L_LoadFile, L_ReadFileStamp, L_BrowseDir

Topics:

Raster Image Functions: Using the Thumbnail Browser

 

Thumbnail Browser

 

Raster Image Functions: Loading Files

 

Raster Image Functions: Redirecting Input and Output

 

Raster Image Functions: Input and Output

Example

 L_INT CreateThumbnailFromFileExample(L_VOID)
{
   BITMAPHANDLE LeadBitmap;
   L_INT nRet;
   THUMBOPTIONS opt;
   L_TCHAR  * szFilename= MAKE_IMAGE_PATH(TEXT("IMAGE1.CMP"));

   //Create a thumbnail with default options, and no callback
   nRet = L_CreateThumbnailFromFile(szFilename, &LeadBitmap, sizeof(BITMAPHANDLE), NULL, NULL, NULL, NULL, NULL);
   if(nRet == SUCCESS)
   {
      if(LeadBitmap.Flags.Allocated)
         L_FreeBitmap(&LeadBitmap);
   }

   //Create a thumbnail with some options, and no callback
   memset(&opt, 0, sizeof(THUMBOPTIONS));
   opt.uStructSize = sizeof(THUMBOPTIONS);
   opt.bLoadStamp = FALSE;
   opt.nHeight = 40;
   opt.nWidth = 80;
   opt.bForceSize = TRUE;
   opt.bMaintainAspect = TRUE;
   opt.crBackColor = RGB(255,0,0);
   nRet = L_CreateThumbnailFromFile(szFilename, &LeadBitmap, sizeof(BITMAPHANDLE), &opt, NULL, NULL, NULL, NULL);
   if(nRet == SUCCESS)
   {
      if(LeadBitmap.Flags.Allocated)
         L_FreeBitmap(&LeadBitmap);
   }
   
   return SUCCESS;
}