LFile::CreateThumbnail

#include "ltwrappr.h"

virtual L_INT LFile::CreateThumbnail(pThumbOptions, pLoadOptions, pFileInfo)

const pTHUMBOPTIONS pThumbOptions;

/* pointer to a structure */

pLOADFILEOPTION pLoadOptions;

/* pointer to optional extended load options */

pFILEINFO pFileInfo;

/* pointer to a structure */

Creates a thumbnail from the specified image file.

Parameter

Description

pThumbOptions

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

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 LFile::GetInfo.

 

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 LFile::GetInfo.has been called previously, but values that affect the size of the image loaded have been changed (for example, by calling LFileSettings::SetPCDResolution or LFileSettings::SetWMFResolution). In this case the FILEINFO structure pointed to by pFileInfo will be updated with the results of LFile::GetInfo.

 

If LFile::GetInfo.has been called prior to calling this function, and no changes have been made to the contents of the structure filled by LFile::GetInfo., 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 LFile::GetInfo.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 LFile::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 LBitmapBase::Free.

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
File format DLLs

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

See Also

Functions:

LFile::LoadFile, LFile::BrowseDir, Class Members, LFileSettings::SetWMFResolution

Topics:

Raster Image Functions: Saving Files

 

Raster Image Functions: Loading and Saving Stamp Images

 

Loading and Saving Images

Example

class MyFileClass : public LFile
{
public: 
   L_INT  CreateThumbnailCallBack(pFILEINFO pFileInfo, 
                                  LBitmapBase* pLBitmap, 
                                  LBuffer* pLBuffer, 
                                  L_UINT uFlags, 
                                  L_INT nRow, 
                                  L_INT nLines); 
};
L_INT  MyFileClass::CreateThumbnailCallBack(pFILEINFO pFileInfo, 
                                            LBitmapBase* pLBitmap, 
                                            LBuffer* pLBuffer, 
                                            L_UINT uFlags, 
                                            L_INT nRow, 
                                            L_INT nLines)
{
   UNREFERENCED_PARAMETER(pFileInfo);
   UNREFERENCED_PARAMETER(pLBitmap);
   UNREFERENCED_PARAMETER(pLBuffer);
   UNREFERENCED_PARAMETER(uFlags);
   UNREFERENCED_PARAMETER(nRow);
   UNREFERENCED_PARAMETER(nLines);
   // Write Your Code here. 
   return SUCCESS;
}
L_INT LFile__CreateThumbnailExample()
{
   LBitmap LeadBitmap; 
   L_INT nRet; 
   THUMBOPTIONS opt; 
   nRet = LeadBitmap.Load (TEXT("%UserProfile%\\My Documents\\LEADTOOLS Images\\lead.cmp"));
   if(nRet != SUCCESS)
      return nRet;
   //Create a thumbnail with default options, and no callback
   nRet = LeadBitmap.File()->CreateThumbnail(NULL, NULL, NULL ); 
   if(nRet != SUCCESS)
      return nRet;
   if(nRet == SUCCESS) 
   {
      nRet = LeadBitmap.Free ();
      if(nRet != SUCCESS)
         return nRet;
   }
   //Create a thumbnail with some options, and no callback
   MyFileClass *Tmp =     new MyFileClass();
   Tmp->SetFileName(TEXT("%UserProfile%\\My Documents\\LEADTOOLS Images\\lead.cmp"));
   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); 
   Tmp->EnableCallBack(TRUE); 
   nRet = Tmp->CreateThumbnail(&opt, NULL, NULL); 
   if(nRet != SUCCESS)
      return nRet;
   return SUCCESS;
}