Funktionreferenz


_GDIPlus_GraphicsDrawImageRectRect

Beschreibung anzeigen in

Zeichnet ein Bild-Objekt und vergrößert, bzw. verkleinert dieses, falls gewünscht

#include <GDIPlus.au3>
_GDIPlus_GraphicsDrawImageRectRect ( $hGraphics, $hImage, $nSrcX, $nSrcY, $nSrcWidth, $nSrcHeight, $nDstX, $nDstY, $nDstWidth, $nDstHeight [, $pAttributes = 0 [, $iUnit = 2]] )

Parameter

$hGraphics Handle zu einem Grafik-Objekt
$hImage Handle zu einem Bild-Objekt
$nSrcX Die X Koordinate der oberen linken Ecke des Quellbildes
$nSrcY Die Y Koordinate der oberen linken Ecke des Quellbildes
$nSrcWidth Breite des Quellbildes
$nSrcHeight Höhe des Quellbildes
$nDstX Die X Koordinate der oberen linken Ecke des Zielbildes
$nDstY Die Y Koordinate der oberen linken Ecke des Zielbildes
$nDstWidth Breite des Zielbildes
$NDstHeight Höhe des Zielbildes
$pAttributes [optional] Pointer auf eine ImageAttributes Struktur welche die Farbe und Größenangaben des zu zeichnenden Bildes enthält. Der Standardwert ist NULL.
$iUnit [optional] Legt die Maßeinheit des Bildes fest

Rückgabewert

Erfolg: True
Fehler: False und setzt das @error Flag auf ungleich 0, das @extended Flag kann den GPSTATUS-Fehlercode ($GDIP_ERR* siehe GPIPlusConstants.au3) enthalten.

Siehe auch

Suche nach GdipDrawImageRectRect in der MSDN Bibliothek.

Beispiel

Beispiel 1

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

Example()

Func Example()
    _GDIPlus_Startup() ; Initialisiert (startet) Microsoft Windows GDI+
    Local Const $iWidth = 600, $iHeight = 600

    Local $hGUI = GUICreate("GDI+ Beispiel (" & @ScriptName & ")", $iWidth, $iHeight) ; Erstellt eine Test GUI
    GUISetState(@SW_SHOW)

    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ; Erstellt ein Grafikobjekt von einem Fensterhandle
    Local $pIA = _GDIPlus_ImageAttributesCreate() ; Erstellt ein ImageAttribute Objekt

    ; Erstellt die Farbmatrix die verwendet wird um die Farben des Bildes zu justieren
    Local $tColorMatrix = _GDIPlus_ColorMatrixCreateTranslate(-1, -1, 0) ; Verwendet eine Translationsfarbmatrix um ein bluaskaliertes Bild zu erstellen

    _GDIPlus_ImageAttributesSetColorMatrix($pIA, 0, True, $tColorMatrix) ; Justiert den ImageAttribute Farbkey Farbmatrix

    Local $hHBmp = _ScreenCapture_Capture("", 0, 0, $iWidth, $iHeight) ; Erstellt ein GDI Bitmap durch einen Screenshot des Desktops
    Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ; Konvertiert GDI in GDI+ Bitmap
    _WinAPI_DeleteObject($hHBmp) ; Gibt GDI Bitmap Ressourcen frei, da diese nicht mehr benötigt werden
    _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hBitmap, 0, 0, $iWidth, $iHeight, 0, 0, $iWidth, $iHeight, $pIA) ; Zeichnet das Bitmap während die Farbjustierung angeandt wird

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Ressourcen freigeben
    _GDIPlus_ImageAttributesDispose($pIA)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
EndFunc   ;==>Example

Beispiel 2

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

Global $g_hGUI, $g_hGfxCtxt, $g_hBitmap, $g_hBMP, $g_hGraphics

Example()

Func Example()
    AutoItSetOption("GUIOnEventMode", 1)

    _GDIPlus_Startup() ;initialize GDI+
    Local Const $iWidth = 600, $iHeight = 600, $iBgColor = 0x303030 ;$iBGColor format RRGGBB

    $g_hGUI = GUICreate("GDI+ Example (" & @ScriptName & ")", $iWidth, $iHeight) ;create a test GUI
    GUISetBkColor($iBgColor, $g_hGUI) ;set GUI background color
    GUISetState(@SW_SHOW)

    ;create buffered graphics frame set for smoother gfx object movements
    $g_hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ;create a graphics object from a window handle
    $g_hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $g_hGraphics)
    $g_hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($g_hBitmap)
    Local Const $iW = 300, $iH = 300
    Local $hHBmp = _ScreenCapture_Capture("", 4, @DesktopHeight - $iH, $iW + 4, @DesktopHeight) ;create a GDI bitmap by capturing an area on desktop
    $g_hBMP = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ;convert GDI to GDI+ bitmap
    _WinAPI_DeleteObject($hHBmp) ;release GDI bitmap resource because not needed anymore
    Local $iVectorX = Random(1.5, 2.5), $iVectorY = Random(1.5, 2.5) ;define x and y vector
    Local $iX = 0.0, $iY = 0.0 ;define start coordinate

    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

    Do
        _GDIPlus_GraphicsClear($g_hGfxCtxt, 0xFF000000 + $iBgColor) ;clear bitmap for repaint
        _GDIPlus_GraphicsDrawImageRectRect($g_hGfxCtxt, $g_hBMP, 0, 0, $iW, $iH, $iX, $iY, $iW / 2, $iH) ;draw bitmap to backbuffer by halving the width
        _GDIPlus_GraphicsDrawImageRect($g_hGraphics, $g_hBitmap, 0, 0, $iWidth, $iHeight) ;copy drawn bitmap to graphics handle (GUI)
        $iX += $iVectorX ;add x vector to current x position
        $iY += $iVectorY ;add y vector to current y position
        If $iX < 0 Or $iX > ($iWidth - $iW / 2) Then $iVectorX *= -1 ;when x border is reached reverse x vector
        If $iY < 0 Or $iY > ($iHeight - $iH) Then $iVectorY *= -1 ;when y border is reached reverse y vector
    Until Not Sleep(20) ;sleep 20 ms to avoid high cpu usage
EndFunc   ;==>Example

Func _Exit()
    ;cleanup GDI+ resources
    _GDIPlus_GraphicsDispose($g_hGfxCtxt)
    _GDIPlus_GraphicsDispose($g_hGraphics)
    _GDIPlus_BitmapDispose($g_hBitmap)
    _GDIPlus_BitmapDispose($g_hBMP)
    _GDIPlus_Shutdown()
    GUIDelete($g_hGUI)
    Exit
EndFunc   ;==>_Exit