UDF > GDIPlus > Graphics >


_GDIPlus_GraphicsDrawImageRect

Desssine une image entière dans un rectangle spécifié d'un contexte graphique

#include <GDIPlus.au3>
_GDIPlus_GraphicsDrawImageRect ( $hGraphics, $hImage, $nX, $nY, $nW, $nH )

Paramètres

$hGraphics Handle de l'objet Graphics
$hImage Handle de l'objet Image
$nX La coordonnée X du coin supérieur gauche du rectangle
$nY La coordonnée Y du coin supérieur gauche du rectangle
$nW Spécifie la largeur du rectangle de destination dans lequel l'image sera dessinée
$nH Spécifie la hauteur du rectangle de destination dans lequel l'image sera dessinée

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 GdipDrawImageRect 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+ Librairie
    _GDIPlus_Startup()

    ; Capture l'écran complet
    $hBitmap1 = _ScreenCapture_Capture("")
    $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap1)

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

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

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

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

    ; Libère les  ressources
    _GDIPlus_ImageDispose($hImage1)
    _GDIPlus_ImageDispose($hImage2)
    _WinAPI_DeleteObject($hBitmap1)
    _WinAPI_DeleteObject($hBitmap2)

    ; Ferme la librairie 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 ; $iBGColor est de la forme 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 de l'objet gfx
    $g_hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ; Crée un objet graphics à partir du handle d'une fenêtre
    $g_hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $g_hGraphics)
    $g_hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($g_hBitmap)
    Local Const $iW = 300, $iH = 300
    Local $hHBmp = _ScreenCapture_Capture("", 0, @DesktopHeight - $iH, $iW, @DesktopHeight) ; create a GDI bitmap by capturing an area on desktop
    $g_hBMP = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ; Convertit le bitmap GDI en GDI+
    _WinAPI_DeleteObject($hHBmp) ; Libère les ressources du bitmap GDI devenues inutiles
    Local $iVectorX = Random(1.5, 2.5), $iVectorY = Random(1.5, 2.5) ; Définit x et y pour un vecteur
    Local $iX = 0.0, $iY = 0.0 ; Définit les coordonnées du départ

    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

    Do
        _GDIPlus_GraphicsClear($g_hGfxCtxt, 0xFF000000 + $iBgColor) ; Efface le bitmap pour le repeindre
        _GDIPlus_GraphicsDrawImageRect($g_hGfxCtxt, $g_hBMP, $iX, $iY, $iW, $iH) ; dessine le  bitmap dans le backbuffer
        _GDIPlus_GraphicsDrawImageRect($g_hGraphics, $g_hBitmap, 0, 0, $iWidth, $iHeight) ; Copie le bitmap dessinée sur le handle graphics (GUI)
        $iX += $iVectorX ; Ajoute x du vecteur au x de la position courante
        $iY += $iVectorY ; Ajoute y du vecteur au y de la position courante
        If $iX < 0 Or $iX > ($iWidth - $iW) Then $iVectorX *= -1 ; Quand le x de la bordure est atteint, le x du vecteur est inversé
        If $iY < 0 Or $iY > ($iHeight - $iH) Then $iVectorY *= -1 ; Quand le y de la bordure est atteint, le y du vecteur est inversé
    Until Not Sleep(20) ; Pause 20 ms pour soulager le CPU
EndFunc   ;==>Example

Func _Exit()
    ; Libère 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