Crée table de couleur RVB à partir d'un tableau de couleur spécifié
#include <WinAPIGdi.au3>
_WinAPI_CreateDIBColorTable ( Const ByRef $aColorTable [, $iStart = 0 [, $iEnd = -1]] )
$aColorTable | Le tableau de couleurs, en RVB, qui va servir à créer la table de couleur du DIB. |
$iStart | [optionnel] L'index du tableau où commencer la création. |
$iEnd | [optionnel] L'index du tableau où cesse la création. |
Succès: | Retourne une structure "dword[n]" qui représente la table de couleur du DIB. |
Échec: | Définit @error <> 0. |
La table de couleur créée par cette fonction est généralement utilisé dans les fonctions _WinAPI_CreateDIB() et _WinAPI_CreateDIBSection() pour créer un bitmap indépendant du périphérique (DIB) avec 1, 4, ou 8 bits par pixel.
_WinAPI_CreateDIB, _WinAPI_CreateDIBSection
#include <GUIConstantsEx.au3> #include <SendMessage.au3> #include <StaticConstants.au3> #include <WinAPIGdi.au3> #include <WinAPIGdiDC.au3> #include <WinAPIHObj.au3> #include <WinAPIMem.au3> #include <WinAPIMisc.au3> ; Crée un tableau de couleur de 256 entrées nécessaire pour un bitmap de 8 bits par pixel Local $aColorTable[256] For $i = 0 To 255 $aColorTable[$i] = _WinAPI_RGB(0, $i, 255 - $i) Next ; Crée la table de couleur à partir du tableau de couleur Local $tColorTable = _WinAPI_CreateDIBColorTable($aColorTable) ; Crée un bitmap indépendant du périphérique (DIB) de 8 bits par pixel and récupère un pointeur sur la position de ses valeurs de bit Local $hBitmap = _WinAPI_CreateDIB(256, 256, 8, $tColorTable, 256) Local $pBits = _WinAPI_GetExtended() ; Remplit les index des couleurs du bitmap For $i = 0 To 255 _WinAPI_FillMemory($pBits + 256 * $i, 256, $i) Next ; Crée une GUI Local $hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 256, 256) Local $idPic = GUICtrlCreatePic('', 0, 0, 256, 256) Local $hPic = GUICtrlGetHandle($idPic) ; Crée un bitmap DDB à partir d'un bitmap DIB pour un affichage correct dans le contrôle Local $hDC = _WinAPI_GetDC($hPic) Local $hDev = _WinAPI_CreateCompatibleBitmap($hDC, 256, 256) Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC) Local $hMemSv = _WinAPI_SelectObject($hMemDC, $hDev) _WinAPI_DrawBitmap($hMemDC, 0, 0, $hBitmap) _WinAPI_ReleaseDC($hPic, $hDC) _WinAPI_SelectObject($hMemDC, $hMemSv) _WinAPI_DeleteDC($hMemDC) ; Définit le bitmap du contrôle $hPic _SendMessage($hPic, $STM_SETIMAGE, 0, $hDev) Local $hObj = _SendMessage($hPic, $STM_GETIMAGE) If $hObj <> $hDev Then _WinAPI_DeleteObject($hDev) EndIf ; Affiche la GUI GUISetState(@SW_SHOW) ; Sauvegarde le bitmap 8 bits par pixel dans un fichier .bmp Local $sPath = FileSaveDialog('Save Image', @TempDir, 'Bitmap Image Files (*.bmp)', 2 + 16, 'MyImage.bmp', $hForm) If $sPath Then _WinAPI_SaveHBITMAPToFile($sPath, $hBitmap, 2834, 2834) EndIf Do Until GUIGetMsg() = $GUI_EVENT_CLOSE