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]] )
$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é |
Succès: | Retourne une structure $tagGDIPBITMAPDATA |
Échec: | Définit @error <> 0 |
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.
_GDIPlus_ImageGetPixelFormat, _WinAPI_DeleteObject
Consultez GdipBitmapLockBits dans la Librairie MSDN.
#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