Function Reference


Gets a thumbnail image from this Image object

#include <GDIPlus.au3>
_GDIPlus_ImageGetThumbnail ( $hImage [, $iWidth = 0 [, $iHeight = 0 [, $bKeepRatio = True [, $hCallback = Null [, $hCallbackData = Null]]]]] )


$hImage  A handle to image object
$iWidth  [optional] Width, in pixels, of the requested thumbnail image. Default is 0.
$iHeight  [optional] Height, in pixels, of the requested thumbnail image. Default is 0.
$bKeepRatio  [optional] If true destination width and height of the image will be recalculated to keep image aspect ratio. Default is True.
$hCallback  [optional] Callback function that you provide. During the process of creating or retrieving the thumbnail image, Microsoft Windows GDI+ calls this function to give you the opportunity to abort the process. The default value is NULL.
$hCallbackData  [optional] Pointer to a block of memory that contains data to be used by the callback function. The default value is NULL.

Return Value

Success: Handle to an Image object that contains the thumbnail image.
Failure: 0 and sets the @error flag to non-zero, @extended may contain GPSTATUS error code ($GPID_ERR*).


A thumbnail image is a small copy of an image. Some image files have a thumbnail image embedded in the file. In such cases, this method retrieves the embedded thumbnail image. If there is no embedded thumbnail image, this method creates a thumbnail image by scaling the main image to the size specified in the thumbWidth and thumbHeight parameters. If both of those parameters are 0, a system-defined size is used.
Don't forget to dispose the thumbnail imgage using _GDIPlus_ImageDispose().


_GDIPlus_GraphicsCreateFromHWND, _GDIPlus_ImageLoadFromFile, _GDIPlus_ImageDispose

See Also

Search GdipGetImageThumbnail in MSDN Library.


#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#include <MsgBoxConstants.au3>


Func Example()
    Local $hImage, $sFile, $hGUI, $hGraphic, $hThumbnail, $iW_new, $iH_new

    $sFile = FileOpenDialog("Please select an image", "", "Image (*.jpg;*.png;*.bmp;*.gif;*.tif)", BitOR($FD_PATHMUSTEXIST, $FD_FILEMUSTEXIST))
    If @error Then Exit MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "No image file has been selected", 30)


    $hImage = _GDIPlus_ImageLoadFromFile($sFile)
    If @error Or Not $hImage Then
        MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "This file isn't supported by GDIPlus!")
        $hGUI = GUICreate("GDI+ _GDIPlus_ImageGetThumbnail Demo", 320, 200)

        $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
        $hThumbnail = _GDIPlus_ImageGetThumbnail($hImage, 96, 96)
        $iW_new = _GDIPlus_ImageGetWidth($hThumbnail)
        $iH_new = _GDIPlus_ImageGetHeight($hThumbnail)
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $hThumbnail, (320 - $iW_new) / 2, (200 - $iH_new) / 2, $iW_new, $iH_new) ;center image in GUI

        Until GUIGetMsg() = $GUI_EVENT_CLOSE


EndFunc   ;==>Example