函数参考


_WinAPI_CreateDIBColorTable

从指定颜色数组创建RGB颜色表

#Include <WinAPIEx.au3>
_WinAPI_CreateDIBColorTable ( Const ByRef $aColorTable [, $iStart [, $iEnd]] )

参数

$aColorTable 创建DIB颜色表的RGB数组
$iStart [可选参数] 开始创建的数组索引
$iEnd [可选参数] 结束创建的数组索引

返回值

成功: 返回代表DIB颜色表的"dword[n]"结构
失败: 返回 0并设置@error非0

注意/说明

由该函数创建的颜色表通常用于_WinAPI_CreateDIB()或_WinAPI_CreateDIBSection()创建每像素1, 4或8位的设备无关位图.

相关

详情参考

None

示例/演示


#Include <APIConstants.au3>
#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global Const $STM_SETIMAGE = 0x0172
Global Const $STM_GETIMAGE = 0x0173

Global $hForm, $Pic, $hPic, $hDC, $hMemDC, $hMemSv, $hBitmap, $pBits, $hDev, $hObj, $Path
Global $aColorTable, $tColorTable

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

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

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

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

; 创建 GUI
$hForm = GUICreate('MyGUI', 256, 256)
$Pic = GUICtrlCreatePic('', 0, 0, 256, 256)
$hPic = GUICtrlGetHandle($Pic)

; Create DDB from DIB to correct display in control
$hDC = _WinAPI_GetDC($hPic)
$hDev = _WinAPI_CreateCompatibleBitmap($hDC, 256, 256)
$hMemDC = _WinAPI_CreateCompatibleDC($hDC)
$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)
$hObj = _SendMessage($hPic, $STM_GETIMAGE)
If $hObj <> $hDev Then
    _WinAPI_DeleteObject($hDev)
EndIf

; Show GUI
GUISetState()

; Save 8 bits-per-pixel bitmap to .bmp file
$Path = FileSaveDialog('Save Image', @ScriptDir, 'Bitmap Image Files (*.bmp)', 2 + 16, @ScriptDir & '\MyImage.bmp', $hForm)
If $Path Then
    _WinAPI_SaveHBITMAPToFile($Path, $hBitmap, 2834, 2834)
EndIf

Do
Until GUIGetMsg() = -3