UDF > GDIPlus > Graphics >


_GDIPlus_GraphicsDrawImage

Dessine un objet Image

#include <GDIPlus.au3>
_GDIPlus_GraphicsDrawImage ( $hGraphics, $hImage, $nX, $nY )

Paramètres

$hGraphics Handle de l'objet Graphics
$hImage Handle de l'objet Image
$nX La coordonnée X du coin supérieur gauche de l'image
$nY La coordonnée Y du coin supérieur gauche de l'image

Valeur de retour

Succès: Retourne True.
Échec: Retourne False et définit @error <> 0, @extended contient le code erreur GPSTATUS ($GPID_ERR*).

Voir aussi

Consultez GdipDrawImage dans la Librairie MSDN.

Exemples

Exemple 1

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

Example()

Func Example()
    Local $hBitmap1, $hBitmap2, $hImage1, $hImage2, $hGraphic

    ; Initialise GDI+
    _GDIPlus_Startup()

    ; Capture un plein écran
    $hBitmap1 = _ScreenCapture_Capture("")
    $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap1)

    ; Capture une région d'écran
    $hBitmap2 = _ScreenCapture_Capture("", 0, 0, 400, 300)
    $hImage2 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap2)

    ; Dessine une image dans une autre
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hImage2, 100, 100)

    ; Dessine un cadre autour de l'image insérée
    _GDIPlus_GraphicsDrawRect($hGraphic, 100, 100, 400, 300)

    ; Enregistre l'image résultante
    _GDIPlus_ImageSaveToFile($hImage1, @MyDocumentsDir & "\GDIPlus_Image.jpg")

    ; Nettoie les ressources
    _GDIPlus_ImageDispose($hImage1)
    _GDIPlus_ImageDispose($hImage2)
    _WinAPI_DeleteObject($hBitmap1)
    _WinAPI_DeleteObject($hBitmap2)

    ; Arrête GDI+
    _GDIPlus_Shutdown()

    ShellExecute(@MyDocumentsDir & "\GDIPlus_Image.jpg")
EndFunc   ;==>Example

Exemple 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() ; Initialise GDI+
    Local Const $iWidth = 600, $iHeight = 600, $iBgColor = 0x303030 ; Le format de $iBGColor est RRGGBB

    $g_hGUI = GUICreate("GDI+ example", $iWidth, $iHeight) ; crée une GUI de test
    GUISetBkColor($iBgColor, $g_hGUI) ; Définit la couleur de fond de la GUI
    GUISetState(@SW_SHOW)

    ; Crée un buffer graphique pour lisser les mouvements d'objets gfx
    $g_hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ; Crée un objet graphique à partir d'un handle de fenêtre
    $g_hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $g_hGraphics)
    $g_hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($g_hBitmap)
    Local $iW = 300, $iH = 300
    Local $hHBmp = _ScreenCapture_Capture("", 0, 0, $iW, $iH) ; Crée un bitmap GDI pour la capture d'une zone du bureau
    $g_hBMP = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ; Convertit le bitmap GDI en GDI+
    _WinAPI_DeleteObject($hHBmp) ; Libére les ressource du bitmap car n'est plus nécessaire
    Local $iVectorX = Random(1.5, 2.5), $iVectorY = Random(1.5, 2.5) ; Définit un vecteur x,y
    Local $iX = 0.0, $iY = 0.0 ; Définit les coordonnéées de départ

    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

    Do
        _GDIPlus_GraphicsClear($g_hGfxCtxt, 0xFF000000 + $iBgColor) ; Efface le bitmap pour le repeindre
        _GDIPlus_GraphicsDrawImage($g_hGfxCtxt, $g_hBMP, $iX, $iY) ; Dessine bitmap dans le backbuffer
        _GDIPlus_GraphicsDrawImageRect($g_hGraphics, $g_hBitmap, 0, 0, $iWidth, $iHeight) ; Copie le bitmap dessinée dans le handle graphique (GUI)
        $iX += $iVectorX ; Ajoute le x du vecteur au x de la position actuelle
        $iY += $iVectorY ; Ajoute le y du vecteur à la position y actuelle
        If $iX < 0 Or $iX > ($iWidth - $iW) Then $iVectorX *= -1 ; Lorsque x bordure est atteint inverse x du vecteur
        If $iY < 0 Or $iY > ($iHeight - $iH) Then $iVectorY *= -1 ; Quand y de frontière est atteint, inverse y du vecteur
    Until Not Sleep(10) ; Pause 10 ms pour éviter une utilisation élevée du processeur
EndFunc   ;==>Example

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