UDF > GDIPlus > Graphics >


_GDIPlus_GraphicsSetPixelOffsetMode

Définit le mode de décalage des pixels d'un objet Graphics

#include <GDIPlus.au3>
_GDIPlus_GraphicsSetPixelOffsetMode ( $hGraphics, $iPixelOffsetMode )

Paramètres

$hGraphics Handle de l'objet Graphics
$iPixelOffsetMode Mode de décalage des pixels:
    0,1,3 - les centres des pixels ont des coordonnées entières
    2,4 - Les centres de pixels ont des coordonnées qui sont à mi-chemin entre les valeurs entières (soit 0,5, 20, 105.5, etc... )

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 GdipSetPixelOffsetMode dans la Librairie MSDN.

Exemple

#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 Const $iWidth = 600, $iHeight = 600, $iBgColor = 0x303030 ; Le format de $iBGColor est 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 graphique dans un buffer pour lisser les mouvements des objets gfx
    $g_hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ; Crée un objet graphique à partir d'un handle fenêtre
    $g_hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $g_hGraphics)
    $g_hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($g_hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($g_hGfxCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ; Définit pour l'objet graphique la qualité de rendu antialiasing
    $g_hPen = _GDIPlus_PenCreate(0xFFFF8060, 2)
    _GDIPlus_GraphicsSetPixelOffsetMode($g_hGfxCtxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)

    Local $aPoints[11][4], $x, $y
    $aPoints[0][0] = 10

    For $y = 0 To 1
        For $x = 1 To 5
            $aPoints[$y * 5 + $x][0] = 100 + 300 * $y + 50 ; Coordonnée x du point
            $aPoints[$y * 5 + $x][1] = 150 + $x * 50 ; Coordonnée y du point
            $aPoints[$y * 5 + $x][2] = Random(-2, 2) ; x vecteur du point
            $aPoints[$y * 5 + $x][3] = Random(-2, 2) ; y vecteur du point
        Next
    Next

    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

    Do
        _GDIPlus_GraphicsClear($g_hGfxCtxt, 0xFF000000 + $iBgColor) ; Efface bitmap pour repeindre
        _GDIPlus_GraphicsDrawClosedCurve2($g_hGfxCtxt, $aPoints, 1.25, $g_hPen) ; Dessine la courbe fermée
        _GDIPlus_GraphicsDrawImage($g_hGraphics, $g_hBitmap, 0, 0) ; Copie le bitmap sur le handle graphique (GUI)
        For $y = 1 To $aPoints[0][0]
            $aPoints[$y][0] += $aPoints[$y][2] ; Calcule la nouvelle position x
            If $aPoints[$y][0] < 0 Or $aPoints[$y][0] > $iWidth Then $aPoints[$y][2] *= -1 ; si bordure verticale est atteinte inverser vecteur x
            $aPoints[$y][1] += $aPoints[$y][3] ; Calcule la nouvelle position y
            If $aPoints[$y][1] < 0 Or $aPoints[$y][1] > $iHeight Then $aPoints[$y][3] *= -1 ; si la bordure horizontale est atteinte inverser y vecteur
        Next
    Until Not Sleep(30) ; Pause 30 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