函数参考


_WinAPI_CompressBitmapBits

从指定位图中创建压缩数据块

#Include <WinAPIEx.au3>
_WinAPI_CompressBitmapBits ( $hBitmap, ByRef $pBuffer [, $iCompression [, $iQuality]] )

参数

$hBitmap 要被压缩的位图的句柄
$pBuffer A pointer to a memory block (buffer) that receives the compressed data. Optionaly, you can set this
parameter to 0 before function call, then the function will allocate the required memory block itself.
Otherwise, it must be a valid memory pointer returned by the _WinAPI_CreateBuffer() function, or
by previously calling this function.
$iCompression [可选参数] 压缩方法. 可为下列值之一:

$COMPRESSION_BITMAP_PNG
$COMPRESSION_BITMAP_JPEG
$iQuality [可选参数] JPEG图像的百分比质量. 无压缩时忽略.

返回值

成功: 保存在$tBuffer中的压缩数据的字节长度.
失败: 返回 0并设置@error非0

注意/说明

实际上,该函数返回的数据是以二进制形式表示.jpeg或.png图像文件.
可以直接使用这些数据以_WinAPI_WriteFile()创建近似的图像文件.

返回的数据通常表示24位色深的jpeg文件或32位色深的png(带或不带alpha层)图像而不依赖于原始位图的色深.

When you no longer need the buffer allocated by this function, you must call the _WinAPI_FreeMemory() function
(do not use any other memory routines) to release occupied memory.

This function internally uses the GDI+ DLL library.

相关

详情参考

None

示例/演示


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

Opt('MustDeclareVars', 1)

Global $tICO, $tHDR, $hFile, $hBitmap, $hSource, $pData = 0, $Bytes, $Length

; Load image
$hSource = _WinAPI_LoadImage(0, @ScriptDir & '\Extras\AutoIt.bmp', $IMAGE_BITMAP, 0, 0, BitOR($LR_LOADFROMFILE, $LR_CREATEDIBSECTION))

; Resize bitmap to 256x256 pixels
$hBitmap = _WinAPI_AdjustBitmap($hSource, 256, 256, $HALFTONE)

; Create compressed PNG data
$Length = _WinAPI_CompressBitmapBits($hBitmap, $pData)

; Create .ico file
If Not @error Then
    $tICO = DllStructCreate('align 1;ushort Reserved;ushort Type;ushort Count;byte Header[20]')
    $tHDR = DllStructCreate('byte Width;byte Height;byte Colors;byte Reserved;word Planes;word BPP;long Size;long Offset', DllStructGetPtr($tICO, 'Header'))
    DllStructSetData($tICO, 'Reserved', 0)
    DllStructSetData($tICO, 'Type', 1)
    DllStructSetData($tICO, 'Count', 1)
    DllStructSetData($tHDR, 'Width', 0)
    DllStructSetData($tHDR, 'Height', 0)
    DllStructSetData($tHDR, 'Colors', 0)
    DllStructSetData($tHDR, 'Reserved', 0)
    DllStructSetData($tHDR, 'Planes', 1)
    DllStructSetData($tHDR, 'BPP', 32)
    DllStructSetData($tHDR, 'Size', $Length)
    DllStructSetData($tHDR, 'Offset', DllStructGetSize($tICO))
    $hFile = _WinAPI_CreateFile(@ScriptDir & '\MyIcon.ico', 1, 4)
    _WinAPI_WriteFile($hFile, DllStructGetPtr($tICO), DllStructGetSize($tICO), $Bytes)
    _WinAPI_WriteFile($hFile, $pData, $Length, $Bytes)
    _WinAPI_CloseHandle($hFile)
EndIf

; Delete unnecessary bitmaps
_WinAPI_DeleteObject($hSource)
_WinAPI_DeleteObject($hBitmap)

; Free memory
_WinAPI_FreeMemory($pData)