Funktionreferenz


_WinAPI_CreateDIBColorTable

Beschreibung anzeigen in

Erzeugt eine RGB Farbtabelle von dem gegebenen Array an Farben.

#include <WinAPIGdi.au3>
_WinAPI_CreateDIBColorTable ( Const ByRef $aColorTable [, $iStart = 0 [, $iEnd = -1]] )

Parameter

$aColorTable Das Array der Farben, in RGB, welche in die DIB Farbtabelle sollen.
$iStart [optional] Der Index des Arrays an dem das Erzeugen beginnen soll.
$iEnd [optional] Der Index des Arrays an dem das Erzeugen angehalten werden soll.

Rückgabewert

Erfolg: Eine "dword[n]" Struktur welche eine DIB Farbtabelle repräsentiert.
Fehler: 0 und setzt das @error Flag auf ungleich null.

Bemerkungen

Die Farbtabelle, welche diese Funktion erzeugt, wird üblicherweise in der _WinAPI_CreateDIB() oder _WinAPI_CreateDIBSection() Funktion verwendet um 1, 4 oder 8 Bits pro Pixel geräteunabhängige Bitmaps (DIB) zu erstellen.

Verwandte Funktionen

_WinAPI_CreateDIB, _WinAPI_CreateDIBSection

Beispiel

#include <GUIConstantsEx.au3>
#include <SendMessage.au3>
#include <StaticConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPIGdiDC.au3>
#include <WinAPIHObj.au3>
#include <WinAPIMem.au3>
#include <WinAPIMisc.au3>

; Create array of colors of 256 entries required for 8 bits-per-pixel bitmap
Local $aColorTable[256]
For $i = 0 To 255
    $aColorTable[$i] = _WinAPI_RGB(0, $i, 255 - $i)
Next

; Create color table from an array of colors
Local $tColorTable = _WinAPI_CreateDIBColorTable($aColorTable)

; Create 8 bits-per-pixel device-independent bitmap (DIB) and retrieve a pointer to the location of its bit values
Local $hBitmap = _WinAPI_CreateDIB(256, 256, 8, $tColorTable, 256)
Local $pBits = _WinAPI_GetExtended()

; Fill bitmap color indexes
For $i = 0 To 255
    _WinAPI_FillMemory($pBits + 256 * $i, 256, $i)
Next

; Create GUI
Local $hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 256, 256)
Local $idPic = GUICtrlCreatePic('', 0, 0, 256, 256)
Local $hPic = GUICtrlGetHandle($idPic)

; Create DDB from DIB to correct display in control
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)

; Set bitmap to control
_SendMessage($hPic, $STM_SETIMAGE, 0, $hDev)
Local $hObj = _SendMessage($hPic, $STM_GETIMAGE)
If $hObj <> $hDev Then
    _WinAPI_DeleteObject($hDev)
EndIf

; Show GUI
GUISetState(@SW_SHOW)

; Save 8 bits-per-pixel bitmap to .bmp file
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