Funktionreferenz


_GDIPlus_ImageScale


Scales an image by a given factor

#include <GDIPlus.au3>
_GDIPlus_ImageScale ( $hImage, $iScaleW, $iScaleH [, $iInterpolationMode = $GDIP_INTERPOLATIONMODE_HIGHQUALITYBICUBIC] )

Parameter

$hImage A handle value
$iScaleW A floating point value
$iScaleH A floating point value
$iInterpolationMode [optional] An integer value. Default is $GDIP_INTERPOLATIONMODE_HIGHQUALITYBICUBIC.

Rückgabewert

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

Bemerkungen

Scale factor greater than 1 means enlarging the image whereas smaller than 1 means decrease the size.

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 / 4, $iH = @DesktopHeight / 4

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

    Local $iScale = 2.75 ;1.0 is without any scaling
    Local $hBitmap_Scaled = _GDIPlus_ImageScale($hBitmap, $iScale, $iScale, $GDIP_INTERPOLATIONMODE_NEARESTNEIGHBOR) ;scale image by 275% (magnify)

    Local $hGUI = GUICreate("GDI+ test", $iW * $iScale, $iH * $iScale, -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 $iScale = 4 ;1.0 is without any scaling
    Local $hBitmap_Scaled = _GDIPlus_ImageScale($hBitmap, $iScale, $iScale, 4)

    Local $hGUI = GUICreate("GDI+ test", $aDim[0] * $iScale, $aDim[1] * $iScale, -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