Function Reference


_GDIPlus_ImageGetThumbnail

Gets a thumbnail image from this Image object

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

Parameters

$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 ($GPIP_ERR* see GPIPlusConstants.au3).

Remarks

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().

Related

_GDIPlus_GraphicsCreateFromHWND, _GDIPlus_ImageLoadFromFile, _GDIPlus_ImageDispose

See Also

Search GdipGetImageThumbnail in MSDN Library.

Example

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

Example()

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(($MB_TOPMOST + $MB_ICONERROR), "Error", "No image file has been selected", 30)

        _GDIPlus_Startup()

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

                $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

                Do
                Until GUIGetMsg() = $GUI_EVENT_CLOSE

                _GDIPlus_ImageDispose($hImage)
                _GDIPlus_ImageDispose($hThumbnail)
        EndIf

        _GDIPlus_Shutdown()
EndFunc   ;==>Example