Funktionreferenz


_GDIPlus_ImageResize


Resize an image to a new given size

#include <GDIPlus.au3>
_GDIPlus_ImageResize ( $hImage, $iNewWidth, $iNewHeight [, $iInterpolationMode = $GDIP_INTERPOLATIONMODE_HIGHQUALITYBICUBIC] )

Parameter

$hImage A handle value
$iNewWidth An integer value
$iNewHeight An integer value
$iInterpolationMode [optional] An integer value. Default is $GDIP_INTERPOLATIONMODE_HIGHQUALITYBICUBIC.

Rückgabewert

Success: a handle to a new Bitmap object
Failure: 0 and sets the @error flag to non-zero.
@error: 1 - unable to create new bitmap
2 - unable to create graphics context
3 - unable to set interpolation mode on graphics context
4 - unable to copy image to scaled bitmap

Bemerkungen

None.

Verwandte Funktionen

_GDIPlus_BitmapCreateFromScan0, _GDIPlus_GraphicsDrawImageRect, _GDIPlus_GraphicsSetInterpolationMode, _GDIPlus_ImageGetGraphicsContext

Beispiel

Beispiel 1

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>
#include <WinAPIHObj.au3>

Example()

Func Example()
    _GDIPlus_Startup()
    Local Const $iW = @DesktopWidth, $iH = @DesktopHeight

    Local $hHBmp = _ScreenCapture_Capture("", 0, 0, $iW, $iH) ;create a GDI bitmap by capturing full screen of the desktop
    Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ;convert GDI bitmap to GDI+ bitmap
    _WinAPI_DeleteObject($hHBmp) ;release GDI bitmap resource because not needed anymore

    Local $hBitmap_Scaled = _GDIPlus_ImageResize($hBitmap, $iW / 4, $iH / 4) ;resize image

    Local $hGUI = GUICreate("GDI+ test", $iW / 4, $iH / 4, -1, -1) ;create a test gui to display the resized image
    GUISetState(@SW_SHOW)

    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap_Scaled, 0, 0) ;display scaled image

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd

    ;cleanup resources
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap_Scaled)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
EndFunc   ;==>Example

Beispiel 2

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

Example()

Func Example()
    ; Load an image
    Local $sFile = FileOpenDialog("Select an image", "", "Image (*.jpg;*.png;*.bmp;*.gif;*.tif)")
    If @error Then Exit MsgBox($MB_ICONWARNING, "Waring", "No image was selected! Exiting script...")

    _GDIPlus_Startup()
    Local $hBitmap = _GDIPlus_ImageLoadFromFile($sFile)
    Local $aDim = _GDIPlus_ImageGetDimension($hBitmap)
    Local $hBitmap_Resized = _GDIPlus_ImageResize($hBitmap, $aDim[0] / 6, $aDim[1] / 6) ;resize image

    Local $hGUI = GUICreate("GDI+ test", $aDim[0] / 6, $aDim[1] / 6, -1, -1) ;create a test gui to display the resized image
    GUISetState(@SW_SHOW)

    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap_Resized, 0, 0) ;display scaled image

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd

    ;cleanup resources
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap_Resized)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
EndFunc   ;==>Example