Dessine un objet Image
#include <GDIPlus.au3>
_GDIPlus_GraphicsDrawImageRectRect ( $hGraphics, $hImage, $nSrcX, $nSrcY, $nSrcWidth, $nSrcHeight, $nDstX, $nDstY, $nDstWidth, $nDstHeight [, $pAttributes = 0 [, $iUnit = 2]] )
$hGraphics | Handle de l'objet Graphics |
$hImage | Handle de l'objet l'image |
$nSrcX | La coordonnée X du coin supérieur gauche de l'image source |
$nSrcY | La coordonnée Y du coin supérieur gauche de l'image source |
$nSrcWidth | Largeur de l'image source |
$nSrcHeight | Hauteur de l'image source |
$nDstX | La coordonnée X du coin supérieur gauche de l'image de destination |
$nDstY | La coordonnée Y du coin supérieur gauche de l'image de destination |
$nDstWidth | Largeur de l'image de destination |
$nDstHeight | Hauteur de l'image de destination |
$pAttributes | [optionnel] handle sur une structure ImageAttributes qui spécifie les attributs couleur et taille de l'image qui doit être dessinée. La valeur par défaut est NULL. |
$iUnit | [optionnel] Spécifie l'unité de mesure de l'image |
Succès: | Retourne True |
Échec: | Retourne False et définit @error <> 0, @extended contient le code erreur GPSTATUS ($GPID_ERR*). |
Consultez GdipDrawImageRectRect dans la Librairie MSDN.
#include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <ScreenCapture.au3> #include <WinAPIHObj.au3> Example() Func Example() _GDIPlus_Startup() ; Initialise GDI+ Local Const $iWidth = 600, $iHeight = 600 Local $hGUI = GUICreate("GDI+ example", $iWidth, $iHeight) ; Crée une fenêtre de test GUISetState(@SW_SHOW) Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ; Crée un objet Graphics à partir du handle de la fenêtre Local $hIA = _GDIPlus_ImageAttributesCreate() ; Crée un objet ImageAttribute ; Crée la matrice des couleurs utilisée pour ajuster les couleurs de l'image Local $tColorMatrix = _GDIPlus_ColorMatrixCreateTranslate(-1, -1, 0) ; Utilise la traduction matricielle des couleurs pour créer une image bleu écaillée _GDIPlus_ImageAttributesSetColorMatrix($hIA, 0, True, $tColorMatrix) ; Régle la couleur-clé de la matrice des couleurs ImageAttribute Local $hHBmp = _ScreenCapture_Capture("", 0, 0, $iWidth, $iHeight) ; Crée un bitmap GDI en capturant une région du bureau Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ; Convertit le bitmap GDI en GDI+ _WinAPI_DeleteObject($hHBmp) ; Libère la ressource du bitmap GDI car elle n'est plus utile _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hBitmap, 0, 0, $iWidth, $iHeight, 0, 0, $iWidth, $iHeight, $hIA) ; Dessine le bitmap tout en appliquant le réglage de la couleur Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ; Nettoie les ressources GDI+ _GDIPlus_ImageAttributesDispose($hIA) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() GUIDelete($hGUI) EndFunc ;==>Example
#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 au format RRGGBB $g_hGUI = GUICreate("GDI+ example", $iWidth, $iHeight) ; Crée une fenêtre de test GUISetBkColor($iBgColor, $g_hGUI) ; Définit la couleur de fond de la GUI GUISetState(@SW_SHOW) ; Crée un buffer graphique pour fluidifier les déplacements de l'objet gfx $g_hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ; Crée un objet Graphics à partir du handle de la 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("", 4, @DesktopHeight - $iH, $iW + 4, @DesktopHeight) ; Crée un bitmap GDI en capturant une région du bureau $g_hBMP = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ; Convertit le bitmap GDI en GDI+ _WinAPI_DeleteObject($hHBmp) ; Libère la ressource du bitmap GDI car elle n'est plus utile Local $iVectorX = Random(1.5, 2.5), $iVectorY = Random(1.5, 2.5) ; Définit les composantes du vecteur direction 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_GraphicsDrawImageRectRect($g_hGfxCtxt, $g_hBMP, 0, 0, $iW, $iH, $iX, $iY, $iW / 2, $iH) ; Dessine le bitmap dans le buffer en réduisant de moitié la largeur _GDIPlus_GraphicsDrawImageRect($g_hGraphics, $g_hBitmap, 0, 0, $iWidth, $iHeight) ; Copie le bitmap dessiné dans le handle graphics (GUI) $iX += $iVectorX ; Ajoute le x du vecteur au x de la position actuelle $iY += $iVectorY ; Ajoute le y du vecteur au y de la position actuelle If $iX < 0 Or $iX > ($iWidth - $iW / 2) Then $iVectorX *= -1 ; Quand l'abscisse de la bordure est atteinte, l'abscisse du vecteur change de signe If $iY < 0 Or $iY > ($iHeight - $iH) Then $iVectorY *= -1 ; Quand l'ordonnée de la bordure est atteinte, l'ordonnées du vecteur change de signe Until Not Sleep(20) ; Pause 20 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