函数参考


_WinAPI_GetGlyphOutline

Retrieves the outline or bitmap for a character in the TrueType font.

#Include <WinAPIEx.au3>
_WinAPI_GetGlyphOutline ( $hDC, $sChar, $iFormat, ByRef $pBuffer [, $tMAT2] )

参数

$hDC A handle to the device context which font is selected.
$sChar The character for which data is to be returned.
$iFormat The format of the data that the function retrieves. This parameter can be one of the following values.

$GGO_BEZIER
$GGO_BITMAP
$GGO_GLYPH_INDEX
$GGO_GRAY2_BITMAP
$GGO_GRAY4_BITMAP
$GGO_GRAY8_BITMAP
$GGO_METRICS
$GGO_NATIVE
$GGO_UNHINTED
$pBuffer A pointer to a memory block (buffer) that receives the outline or bitmap 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. If the $GGO_METRICS is specified, this parameter is
ignored, and function only returns the information about a glyph (see below).
$tMAT2 [可选参数] $tagMAT2 structure specifying a transformation matrix for the character. If this parameter is
0 or omitted, the transformation will not be used (it is identity matrix).

返回值

Success $tagGLYPHMETRICS structure containing information about the placement and orientation of a glyph,
失败: 返回 0 并设置 @error 标志为非 0 值.

注意/说明

Note that, for the $GGO_GRAY... values, the function retrieves a glyph bitmap that contains n^2+1 (n squared plus
one) levels of gray.

The glyph bitmap returned by _WinAPI_GetGlyphOutline() when $GGO_BITMAP is specified is a DWORD-aligned, row-oriented,
monochrome bitmap. When $GGO_GRAY2_BITMAP is specified, the bitmap returned is a DWORD-aligned, row-oriented array
of bytes whose values range from 0 to 4. When $GGO_GRAY4_BITMAP is specified, the bitmap returned is a DWORD-aligned,
row-oriented array of bytes whose values range from 0 to 16. When $GGO_GRAY8_BITMAP is specified, the bitmap
returned is a DWORD-aligned, row-oriented array of bytes whose values range from 0 to 64.

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.

相关

详情参考

在MSDN中搜索


示例/演示


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

Opt('MustDeclareVars', 1)

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

Global $hForm, $Pic, $hPic, $tGM, $W, $H, $hDC, $hSv, $hBmp, $hDib, $hFont, $pData = 0
Global $aColorTable[2] = [0xFFFFFF, 0xC00000]

; Creates logical font ("Times") and retrieve bitmap bits for a random character
$hDC = _WinAPI_CreateCompatibleDC(0)
$hFont = _WinAPI_CreateFont(512, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS,$CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Times')
$hSv = _WinAPI_SelectObject($hDC, $hFont)
$tGM = _WinAPI_GetGlyphOutline($hDC, ChrW(Random(65, 90, 1)), $GGO_BITMAP, $pData)
$W = DllStructGetData($tGM, 'BlackBoxX')
$H = DllStructGetData($tGM, 'BlackBoxY')
_WinAPI_SelectObject($hDC, $hSv)
_WinAPI_DeleteObject($hFont)

; Create 1 bits-per-pixel bitmap
$hBmp = _WinAPI_CreateBitmap(32 * Ceiling($W / 32), $H, 1, 1, $pData)

; Crop bitmap to the required size and colorize it
$hDib = _WinAPI_CreateDIB($W, $H, 1, _WinAPI_CreateDIBColorTable($aColorTable), 2)
$hSv = _WinAPI_SelectObject($hDC, $hDib)
_WinAPI_DrawBitmap($hDC, 0, 0, $hBmp, $MERGEPAINT)
_WinAPI_SelectObject($hDC, $hSv)
_WinAPI_DeleteObject($hBmp)

; Free unnecessary resources
_WinAPI_FreeMemory($pData)
_WinAPI_DeleteDC($hDC)

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

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

; Show GUI
GUISetState()

Do
Until GUIGetMsg() = -3