Crée un objet crayon
#include <GDIPlus.au3>
_GDIPlus_PenCreate ( [$iARGB = 0xFF000000 [, $nWidth = 1 [, $iUnit = 2]]] )
$iARGB | [optionnel] Code couleur du crayon: composantes Alpha, Rouge, Vert et Bleu |
$nWidth | [optionnel] Largeur du crayon mesurée dans l'unité spécifiée dans le paramètre $iUnit |
$iUnit | [optionnel] Unité de mesure de la largeur du crayon: 0 - Coordonnées universelles, une unité non physique 1 - Unité d'affichage 2 - Unité de 1 pixel 3 - Unité de 1 point ou 1/72 de pouce 4 - Unité de 1 pouce 5 - Unité de 1/300 pouces 6 - Unité de 1 millimètre |
Succès: | Retourne le handle d'un objet crayon. |
Échec: | Retourne 0 et définit @error <> 0, @extended contient le code erreur GPSTATUS ($GPID_ERR*). |
Lorsque vous en avez terminé avec le crayon, appelez _GDIPlus_PenDispose() pour libérer les ressources.
Cherchez GdipCreatePen1 dans la Library MSDN.
#include <GDIPlus.au3> #include <GUIConstantsEx.au3> Example() Func Example() Local $hGUI, $hGraphic, $hPen ; Crée une fenêtre GUI $hGUI = GUICreate("GDI+", 400, 300) GUISetState(@SW_SHOW) ; Dessine le segment _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hPen = _GDIPlus_PenCreate() _GDIPlus_GraphicsDrawLine($hGraphic, 10, 150, 390, 150, $hPen) ; Boucle jusqu'à ce que l'utilisateur décide d'arrêter. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ; Nettoie les ressources _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() EndFunc ;==>Example
#include <GDIPlus.au3> #include <GUIConstantsEx.au3> Global $g_hGUI, $g_hGraphics, $g_hBitmap, $g_hGfxCtxt, $g_hPen Example() Func Example() AutoItSetOption("GUIOnEventMode", 1) _GDIPlus_Startup() ; Initialise GDI+ Local $iW = 600, $iH = 600 Local Const $iBgColor = 0x303030 ; Le format de $iBGColor est RRGGBB $g_hGUI = GUICreate("GDI+ example", $iW, $iH) ;créer une interface de test GUISetBkColor($iBgColor, $g_hGUI) ;définir l'interface graphique couleur de fond GUISetState(@SW_SHOW) ; Crée un buffer graphique pour lisser les objets gfx en mouvement $g_hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ; Crée un objet graphique à partir du handle de la fenêtre $g_hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $g_hGraphics) $g_hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($g_hBitmap) _GDIPlus_GraphicsSetSmoothingMode($g_hGfxCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ; Définit un objet graphique avec qualité de rendu antialiasing $g_hPen = _GDIPlus_PenCreate(0xFF8080FF, 2) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") Local Const $fDeg = ACos(-1) / 180, $iRadius = 300, $iWidth = $iW / 2, $iHeight = $iH / 2 Local $fAngle = 0 Do _GDIPlus_GraphicsClear($g_hGfxCtxt, 0xFF000000 + $iBgColor) ;Efface le bitmap pour le repeindre _GDIPlus_GraphicsDrawEllipse($g_hGfxCtxt, $iWidth - $iRadius / 2 + $iRadius / 18, $iHeight - $iRadius / 2 + $iRadius / 18, $iRadius - $iRadius / 9, $iRadius - $iRadius / 9, $g_hPen) ;dessiner une ellipse _GDIPlus_GraphicsDrawLine($g_hGfxCtxt, $iWidth + Cos($fAngle * $fDeg) * $iRadius, $iHeight + Sin($fAngle * $fDeg) * $iRadius, _ ; Trace une ligne $iWidth + Cos($fAngle * $fDeg + 180) * $iRadius, $iHeight + Sin($fAngle * $fDeg + 180) * $iRadius, $g_hPen) _GDIPlus_GraphicsDrawImageRect($g_hGraphics, $g_hBitmap, 0, 0, $iW, $iH) ; Copie le bitmap dessinée avec le handle graphique (GUI) $fAngle += 0.5 Until Not Sleep(20) ; Pause de 20 ms pour éviter une utilisation élevée du processeur EndFunc ;==>Example Func _Exit() ; Nettoie les ressources GDI+ _GDIPlus_PenDispose($g_hPen) _GDIPlus_GraphicsDispose($g_hGfxCtxt) _GDIPlus_GraphicsDispose($g_hGraphics) _GDIPlus_BitmapDispose($g_hBitmap) _GDIPlus_Shutdown() GUIDelete($g_hGUI) Exit EndFunc ;==>_Exit