本帖最后由 zghwelcome 于 2020-5-22 14:21 编辑
这是下面代码输出的结果,模糊而有锯齿
#include <GDIPlus.au3>
Local $sText = '文字模糊,有锯齿'
Local $iW = 250, $iH = 40, $iFontSize = 20
_GDIPlus_Startup()
Local $hImage = _GDIPlus_BitmapCreateFromScan0($iW, $iH, $GDIP_PXF32PARGB)
_GDIPlus_BitmapSetResolution($hImage, 96,96) ;//调整图像的水平、垂直DPI
Local $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
DllCall($__g_hGDIPDll, "int", "GdipSetTextRenderingHint", "hwnd", $hGraphic, "int", 4) ;1:无效,0:系统默认,1:最佳性能,2:最佳质量,3:不处理,4:抗锯齿
;背景色填充成白色
_GDIPlus_GraphicsClear($hGraphic, 0xffffffff)
;/ 图像绘制文字
$hBrush = _GDIPlus_BrushCreateSolid(0xFFff0000)
$hFormat = _GDIPlus_StringFormatCreate(0)
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, 1) ;//字体大小
$tLayout = _GDIPlus_RectFCreate(3, 8, $iW, $iH)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $sText, $hFont, $tLayout, $hFormat, $hBrush)
;//输出文件
Local $giQuality = 100, $pParams
Local $tParams = _GDIPlus_ParamInit(1)
Local $tData = DllStructCreate('int Quality')
DllStructSetData($tData, 'Quality', $giQuality)
_GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, DllStructGetPtr($tData))
If IsDllStruct($tParams) Then $pParams = DllStructGetPtr($tParams)
Local $CLSID = _GDIPlus_EncodersGetCLSID('JPG')
_GDIPlus_ImageSaveToFileEx($hImage, @ScriptDir & '\___Out.jpg', $CLSID, $pParams)
ShellExecute(@ScriptDir & '\___Out.jpg')
;//销毁
$tData = 0
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
;//调整图像的水平、垂直DPI
Func _GDIPlus_BitmapSetResolution($hBitmap, $nDpiX, $nDpiY)
Local $aResult = DllCall($__g_hGDIPDll, "uint", "GdipBitmapSetResolution", "hwnd", $hBitmap, "float", $nDpiX, "float", $nDpiY)
If @error Then Return SetError(@error, @extended, False)
$GDIP_STATUS = $aResult[0]
Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_BitmapSetResolution
|