Dessine une ligne (segment)
#include <GDIPlus.au3>
_GDIPlus_GraphicsDrawLine ( $hGraphics, $nX1, $nY1, $nX2, $nY2 [, $hPen = 0] )
$hGraphics | Handle de l'objet Graphics |
$nX1 | La coordonnée X du point de départ de la ligne |
$nY1 | La coordonnée Y du point de départ de la ligne |
$nX2 | La coordonnée X du point final de la ligne |
$nY2 | La coordonnée Y du point final de la ligne |
$hPen | [optionnel] Handle de l'objet Pen qui sera utilisé pour dessiner la ligne. Si 0, un crayon noir qui trace des lignes continues de largeur 1 sera utilisé. |
Succès: | Retourne True. |
Échec: | Retourne False et définit @error <> 0, @extended contient le code erreur GPSTATUS ($GPID_ERR*). |
Voir GdipDrawLine dans la Librairie 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