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