UDF > GDIPlus > Bitmap >


_GDIPlus_BitmapSetPixel

Définit la couleur d'un pixel d'un bitmap

#include <GDIPlus.au3>
_GDIPlus_BitmapSetPixel ( $hBitmap, $iX, $iY, $iARGB )

Paramètres

$hBitmap Handle de l'objet Bitmap
$iX La coordonnée X du pixel
$iY La coordonnée Y du pixel
$iARGB La nouvelle couleur du pixel

Valeur de retour

Succès: Retourne True.
Échec: Retourne False et définit @error <> 0, @extended contient le code erreur GPSTATUS ($GPID_ERR*).

En relation

_GDIPlus_BitmapGetPixel

Voir aussi

Consultez GdipBitmapSetPixel dans la Librairie MSDN.

Exemple

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>
#include <WinAPIHObj.au3>

Example()

Func Example()
    _GDIPlus_Startup() ; Initialise GDI+
    Local Const $iWidth = 150, $iHeight = 150
    Local $iColor = 0
    Local $hHBmp = _ScreenCapture_Capture("", 0, @DesktopHeight - $iHeight, $iWidth, @DesktopHeight) ; Crée un bitmap GDI an capturant une zone sur le bureau
    Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ; Convertit le bitmap GDI en GDI+
    _WinAPI_DeleteObject($hHBmp) ; Libére le bitmap GDI car n'est plus nécessaire
    Local $iR, $iG, $iB, $iGrey
    For $iY = 0 To $iHeight - 1
        For $iX = 0 To $iWidth - 1
            $iColor = _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY) ; Obtient la couleur de pixel courant
            $iR = BitShift(BitAND($iColor, 0x00FF0000), 16) ; Extrait le canal de couleur rouge
            $iG = BitShift(BitAND($iColor, 0x0000FF00), 8) ; Extrait le canal de couleur vert
            $iB = BitAND($iColor, 0x000000FF) ; Extrait le canal de couleur bleu
            $iGrey = Hex(Int(($iR + $iG + $iB) / 3), 2) ; Convertit les pixels en niveaux de gris
            ; On montre que la moyenne arithmétiques des composantes définit, sur la diagonale des gris,
            ; le point le plus proche (projection orthogonale)
            _GDIPlus_BitmapSetPixel($hBitmap, $iX, $iY, "0xFF" & $iGrey & $iGrey & $iGrey) ; Définit le pixel en niveaux de gris
        Next
    Next
    Local $hGUI = GUICreate("GDI+ example", $iWidth, $iHeight) ; Crée une GUI de test
    GUISetState(@SW_SHOW)

    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ; Crée un objet graphique à partir du handle de la fenêtre
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0) ; Copie le bitmap négatif dans l'objet graphique (GUI)

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Nettoie les ressources  GDI+
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
EndFunc   ;==>Example