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