UDF > GDIPlus > Bitmap >


_GDIPlus_BitmapLockBits

Verrouille une partie rectangulaire d'un bitmap pour la lecture ou l'�criture

#include <GDIPlus.au3>
_GDIPlus_BitmapLockBits ( $hBitmap, $iLeft, $iTop, $iWidth, $iHeight [, $iFlags = $GDIP_ILMREAD [, $iFormat = $GDIP_PXF32RGB]] )

Param�tres

$hBitmap Handle de l'objet Bitmap
$iLeft Coordonn�e X de l'angle sup�rieur gauche du rectangle � verrouiller
$iTop Coordonn�e Y de l'angle sup�rieur gauche du rectangle � verrouiller
$iWidth Largeur du rectangle � verrouiller
$iHeight Hauteur du rectangle � verrouiller
$iFlags [optionnel] Ensemble de flags qui sp�cifie si la partie verrouill�e du bitmap est disponible pour la lecture ou l'�criture et si une m�moire tampon est deja allou�e. Peut �tre une combinaison des �l�ments suivants :
    $GDIP_ILMREAD - Une partie de l'image est verrouill�e pour la lecture
    $GDIP_ILMWRITE - Une partie de l'image est verrouill�e pour l'�criture
    $GDIP_ILMUSERINPUTBUF - Une m�moire tampon est allou�e par l'utilisateur
$iFormat [optionnel] Sp�cifie le format des pixels dans la m�moire tampon temporaire. Peut prendre une des valeurs suivantes:
    $GDIP_PXF01INDEXED - 1 bpp, index�
    $GDIP_PXF04INDEXED - 4 bpp, index�
    $GDIP_PXF08INDEXED - 8 bpp, index�
    $GDIP_PXF16GRAYSCALE - 16 bpp, niveaux de gris
    $GDIP_PXF16RGB555 - 16 bpp; 5 bits pour chaque composante RVB
    $GDIP_PXF16RGB565 - 16 bpp; 5 bits pour la composante rouge, 6 bits pour la composante verte, and 5 bits pour la composante bleue
    $GDIP_PXF16ARGB1555 - 16 bpp; 1 bit pour la composante de transparence and 5 bits pour chaque composante RVB
    $GDIP_PXF24RGB - 24 bpp; 8 bits pour chaque composante RVB
    $GDIP_PXF32RGB - 32 bpp; 8 bits pour chaque composante RVB. Pas de composante de transparence
    $GDIP_PXF32ARGB - 32 bpp; 8 bits pour chaque composante RVB et composante de transparence
    $GDIP_PXF32PARGB - 32 bpp; 8 bits pour chaque composante RVB et composante de transparence, pr�-multipli�

Valeur de retour

Succ�s: Retourne une structure $tagGDIPBITMAPDATA
�chec: D�finit @error <> 0

Remarque

La fonction verrouille, en m�moire, une partie rectangulaire d'un bitmap et fournit une m�moire tampon temporaire que vous utilisez pour lire ou �crire des pixels dans le format indiqu�. Toutes les donn�es de la m�moire tampon sont ensuite recopi�es quand vous appelez _GDIPlus_BitmapUnlockBits() pour lib�rer le verrouillage de la partie de l'image.

En relation

_GDIPlus_ImageGetPixelFormat, _WinAPI_DeleteObject

Voir aussi

Consultez GdipBitmapLockBits dans la Librairie MSDN.

Exemple

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Support d'ex�cution X64
    Local $sWow64 = ""
    If @AutoItX64 Then $sWow64 = "\Wow6432Node"

    ; Obtient le r�pertoire d'installation de AutoIt
    Local $sRegPath = "HKLM\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt"

    Local $sFile = RegRead($sRegPath, "InstallDir") & "\Examples\GUI\logo4.gif"
    If Not FileExists($sFile) Then
        MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", $sFile & " not found!", 30)
        Return False
    EndIf

    _GDIPlus_Startup()
    Local $hImage = _GDIPlus_ImageLoadFromFile($sFile) ; Cr�e un objet d'image � partir d'un fichier
    If @error Then
        _GDIPlus_Shutdown()
        MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "An error has occured - unable to load image!", 30)
        Return False
    EndIf

    Local $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage) ; Obtient la largeur et la hauteur de l'image
    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH, $GDIP_PXF32ARGB )
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsDrawImageRect($hContext, $hImage, 0, 0, $iW, $iH)

    Local $tBitmapData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $iW, $iH, BitOR($GDIP_ILMWRITE, $GDIP_ILMREAD), $GDIP_PXF32ARGB) ; Verrouille une partie d'une image bitmap pour la lecture et l'�criture. Plus d'info � http://msdn.microsoft.com/en- us/library/windows/desktop/ms536298(v=vs.85).aspx
    Local $iScan0 = DllStructGetData($tBitmapData, "Scan0") ; Obtient le champ nomm� "Scan0" de la structure $tBitmapData (donn�es de pixels)
    Local $iSearchPixel = Int(0xFF000080), $iReplaceColor = 0x00000000 ; Format de couleur 0xAARRVVBB
    Local $tPixel = DllStructCreate("int[" & $iW * $iH & "];", $iScan0)
    Local $iPixel, $iRowOffset

    For $iY = 0 To $iH - 1
        $iRowOffset = $iY * $iW + 1
        For $iX = 0 To $iW - 1 ; Obtient chaque pixel de chaque ligne et de chaque colonne
            $iPixel = DllStructGetData($tPixel, 1, $iRowOffset + $iX) ; Obtient la couleur des pixels
            If $iPixel = $iSearchPixel Then DllStructSetData($tPixel, 1, $iReplaceColor, $iRowOffset + $iX) ; Compare et remplace la couleur des pixels (bleu avec la couleur transparente)
        Next
    Next
    _GDIPlus_BitmapUnlockBits($hBitmap, $tBitmapData) ; D�verrouille une partie d'une image bitmap qui a �t� verrouill�e par _GDIPlus_BitmapLockBits

    ; Pour enregistrer l'image manipul�e il suffit d'utiliser _GDIPlus_ImageSaveToFile()

    ShellExecute($sFile) ; Affiche l'image originale juste pour comparer avec celle manipul�e

    ; Affiche l'image manipul�e
    Local $hGUI = GUICreate("_GDIPlus_BitmapLockBits Demo", $iW, $iH)
    GUISetState(@SW_SHOW)

    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) ; Cr�e un objet Graphics � partir d'un handle de fen�tre
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iW, $iH) ; Copie l'image manipul�e dans le handle graphique

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Nettoie
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hContext)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
EndFunc   ;==>Example