函数参考


_WinAPI_CreateANDBitmap

Creates AND bitmask device-independent bitmap (DIB) from the specified bitmap.

#Include <WinAPIEx.au3>
_WinAPI_CreateANDBitmap ( $hBitmap )

参数

$hBitmap Handle to the bitmap from which to create AND bitmask DIB.

返回值

Success Handle to the DIB.
失败: 返回 0 并设置 @error 标志为非 0 值.

注意/说明

The _WinAPI_CreateANDBitmap() creates a 1 bits-per-pixel AND bitmask DIB from the 32 bits-per-pixel DIB or DDB.
If the source bitmap is non 32 bits-per-pixel bitmap, or is a compressed bitmap, the function fails.

You can use the bitmap returned by this function to create icon by using the _WinAPI_CreateIconIndirect().

When you are finished using the bitmap, destroy it using the _WinAPI_DeleteObject() function.

相关

详情参考

None

示例/演示


#Include <GDIPlus.au3>
#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global Const $sPng = @ScriptDir & '\Extras\Silverlight.png'

Global Const $STM_SETIMAGE = 0x0172

Global $hForm, $Pic[2], $hBitmap[2], $hPng, $hIcon, $Width, $Height, $Path

; Create 32 bits-per-pixel bitmap from a PNG image
_GDIPlus_Startup()
$hPng = _GDIPlus_ImageLoadFromFile($sPng)
$hBitmap[0] = _GDIPlus_BitmapCreateDIBFromBitmap($hPng)
$Width = _GDIPlus_ImageGetWidth($hPng)
$Height = _GDIPlus_ImageGetHeight($hPng)
_GDIPlus_ImageDispose($hPng)
_GDIPlus_Shutdown()

; Create 1 bits-per-pixel AND bitmask bitmap
$hBitmap[1] = _WinAPI_CreateANDBitmap($hBitmap[0])

; 创建 GUI
$hForm = GUICreate('MyGUI', $Width * 2, $Height)
$Pic[0] = GUICtrlCreatePic('', 0, 0, $Width, $Height)
$Pic[1] = GUICtrlCreatePic('', $Width, 0, $Width, $Height)

; Set both bitmaps to controls
For $i = 0 To 1
    GUICtrlSendMsg($Pic[$i], $STM_SETIMAGE, 0, $hBitmap[$i])
Next

; Show GUI
GUISetState()

; Create and save icon to .ico file
$Path = FileSaveDialog('Save Icon', @ScriptDir, 'Icon Files (*.ico)', 2 + 16, _WinAPI_PathStripPath(_WinAPI_PathRenameExtension($sPng, '.ico')), $hForm)
If $Path Then
    $hIcon = _WinAPI_CreateIconIndirect($hBitmap[0], $hBitmap[1])
    If Not @error Then
        _WinAPI_SaveHICONToFile($Path, $hIcon)
        _WinAPI_DestroyIcon($hIcon)
    EndIf
EndIf

Do
Until GUIGetMsg() = -3

; Unlike _GDIPlus_BitmapCreateHBITMAPFromBitmap() that creates a device-dependent bitmap (DDB), this function creates a device-independent bitmap (DIB) which may be used for semi-transparent images

Func _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap)

    Local $hDIB = 0, $aSize, $tData, $pBits

    $aSize = DllCall($ghGDIPDll, 'uint', 'GdipGetImageDimension', 'ptr', $hBitmap, 'float*', 0, 'float*', 0)
    If (@error) Or ($aSize[0]) Then
        Return 0
    EndIf
    $tData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $aSize[2], $aSize[3], $GDIP_ILMREAD, $GDIP_PXF32ARGB)
    $pBits = DllStructGetData($tData, 'Scan0')
    If Not $pBits Then
        Return 0
    EndIf
    $hDIB = _WinAPI_CreateDIB($aSize[2], $aSize[3])
    If Not @error Then
        _WinAPI_SetBitmapBits($hDIB, $aSize[2] * $aSize[3] * 4, $pBits)
    EndIf
    _GDIPlus_BitmapUnlockBits($hBitmap, $tData)
    Return $hDIB
EndFunc   ;==>_GDIPlus_BitmapCreateDIBFromBitmap