ShellBrowser Delphi Components Documentation
ContentsIndexHome
PreviousUpNext
Jam.Shell.Thumbnail.TJamThumbnailExtractor.GetThumbnailBitmap

Use GetThumbnailBitmap to get a TBitmap thumbnail of the file represented by the passed ItemIdList. It copies a thumbnail preview to the given Bitmap/Image.

Syntax
Pascal
class function GetThumbnailBitmap(const pItemIdList: IItemIdList; const pWidth: Integer; const pHeight: Integer; const pIconInstead: Boolean = False; const pBackgroundColor: TColor = clNone; const pCachedOnly: boolean = false): TBitmap;
Parameters 
Description 
const pItemIdList: IItemIdList 
The ItemIdList to get the thumbnail for. 
const pWidth: Integer 
The width for the thumbnail. 
const pHeight: Integer 
The height for the thumbnail. 
const pIconInstead: Boolean = False 
If set to True, the Icon is used as the thumbnail. This is much faster than retrieving the thumbnail.  
const pBackgroundColor: TColor = clNone 
An optional background color to be used for the resulting bitmap. 
const pCachedOnly: boolean = false 
Only retrieve the thumbnail, if it is already cached. This avoids delays. If true, pIconInstead is ignored, and assumed true. 

TBitmap

GetThumbnailBitmap generates a thumbnail of the current file and assigns it to the Bitmap that was passed as argument. The size of the generated Thumbnail may be adjusted using the Width and Height property of the Bitmap. The function returns true if the thumbnail was generated successfully and false otherwise. The function works similar to GetThumbnailAsImage

If you call this function for a thread, COM must be initialized using CoInitializeEx(). For informations about CoInitializeEx() see https://docs.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-coinitializeex.

This procedure for the VCL version creates a thumbnail image of a file and saves it to a JPEG-file. The path to the source file and the path of the resulting JPEG-file must be given when procedure is called. The height and width of the thumbnail image are optional parameters that have a default value of 100. Borland's jpeg unit must be included in the uses clause.

uses jpeg, jamitemidlist, graphics, jam.shell.thumbnail;
  procedure GetThumbnail(aSourceFilePath, aThumbnailFilename: String;
                        ThumbnailWidth: integer = 100;
                        ThumbnailHeight: integer = 100);
  var
    jpegImage : TJPEGImage;
    bitmap : TBitmap;
    itemIdList: IItemIdList;
  begin
    itemIdList := TJamItemIdList.Create(aSourceFilePath);
    jpegImage := TJPEGImage.Create;
    try
      bitmap := TJamThumbnailExtractor.GetThumbnailBitmap(itemIdList, ThumbnailWidth, ThumbnailHeight);
      if assigned(bitmap) then begin //if the file doesn't have a thumbnail, the bitmap will not be assigned.
        try
          jpegImage.Assign(bitmap);
          jpegImage.CompressionQuality := 85;
          jpegImage.Compress;
          jpegImage.Savetofile(aThumbnailFilename);
        finally
          bitmap.Free;
        end;//try..finally bitmap
      end;
      finally
        jpegimage.Free;
      end;//try..finally jpegimage
  end;