Crée un objet Bitmap à partir d'un objet Graphics, avec une largeur et une hauteur données
#include <GDIPlus.au3>
_GDIPlus_BitmapCreateFromGraphics ( $iWidth, $iHeight, $hGraphics )
$iWidth | Spécifie la largeur, en pixels, du bitmap |
$iHeight | Spécifie la hauteur, en pixels, du Bitmap |
$hGraphics | Handle de l'objet Graphics |
Succès: | Retourne le handle de l'objet Bitmap |
Échec: | Retourne 0 et définit @error <> 0, @extended contient le code erreur GPSTATUS ($GPID_ERR*). |
Lorsque vous en avez terminé avec l'objet bitmap, appelez _GDIPlus_BitmapDispose() pour libérer les ressources
Consultez GdipCreateBitmapFromGraphics dans la Librairie MSDN.
#include <GDIPlus.au3> #include <GUIConstantsEx.au3> Global $g_hGUI, $g_hBrush, $g_hGfx, $g_hGfxCtxt, $g_hBitmap 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 interface de test GUISetBkColor($iBgColor, $g_hGUI) ; définir l'interface graphique couleur de fond GUISetState(@SW_SHOW) ; Créer un buffer graphique pour fluidifier les déplacements d'objets $g_hGfx = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ; créer un objet graphique à partir d'un handle fenêtre $g_hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $g_hGfx) ; Crée un objet Bitmap basé sur un objet graphique $g_hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($g_hBitmap) ; Obtient le contexte graphique de l'image/bitmap pour dessiner dans l'image/bitmap _GDIPlus_GraphicsSetSmoothingMode($g_hGfxCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ; Définit pour l'objet graphique la qualité de rendu antialiasing $g_hBrush = _GDIPlus_BrushCreateSolid(0xFF8080FF) ; Crée un objet Brush solide GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") Local Const $iDeg = ACos(-1) / 180 ; ACos(-1) est presque pi Local $iSize = 50, $iX_Center = ($iWidth - $iSize) / 2, $iY_Center = ($iHeight - $iSize) / 2, $iXPos, $iYPos, $iAngle = 0 Local Const $iDots = 16, $iAngelDist = 360 / $iDots, $iRadius = 200 Do _GDIPlus_GraphicsClear($g_hGfxCtxt, 0xFF000000 + $iBgColor) ; Efface le bitmap avec une couleur donnée (en format AARRGGBB) For $i = 1 To $iDots $iXPos = $iX_Center + Cos($iAngle * $iDeg) * $iRadius $iYPos = $iY_Center + Sin($iAngle * $iDeg) * $iRadius _GDIPlus_GraphicsFillEllipse($g_hGfxCtxt, $iXPos, $iYPos, $iSize, $iSize, $g_hBrush) ; Dessine des points dans un cercle $iAngle += $iAngelDist ; Augmente l'angle pour le prochain point Next $iAngle += 1 ; Augmente l'angle global _GDIPlus_GraphicsDrawImageRect($g_hGfx, $g_hBitmap, 0, 0, $iWidth, $iHeight) ; Copie le bitmap dessiné dans la GUI Until Not Sleep(20) ; Sleep() retourne toujours 1 et non 1 ou 0 EndFunc ;==>Example Func _Exit() ; Nettoie les ressources GDI+ _GDIPlus_BrushDispose($g_hBrush) _GDIPlus_GraphicsDispose($g_hGfxCtxt) _GDIPlus_GraphicsDispose($g_hGfx) _GDIPlus_BitmapDispose($g_hBitmap) _GDIPlus_Shutdown() GUIDelete($g_hGUI) Exit EndFunc ;==>_Exit