首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> Delphi

再學GDI+[45]: 文字渲染品質控制 - SetTextRenderingHint 六種模式完整對比

     編輯:Delphi

前言

TGPGraphics.SetTextRenderingHint 控制文字光柵化品質。本文提供六種模式即時切換對比,從系統預設到 ClearType 最高品質,幫助開發者在效能與視覺品質間取得最佳平衡。

六大渲染模式詳細對照

索引Delphi 列舉微軟列舉技術特點品質速度
0TextRenderingHintSystemDefaultSystemDefault跟隨系統字體平滑設定視系統而定快
1TextRenderingHintSingleBitPerPixelGridFitSingleBitPerPixelGridFit單位素位圖 + 網格適配(無抗鋸齒)低最快
2TextRenderingHintSingleBitPerPixelSingleBitPerPixel單位素位圖(無提示、無抗鋸齒)最低極快
3TextRenderingHintAntiAliasGridFitAntiAliasGridFit抗鋸齒 + 網格適配(推薦通用)高中
4TextRenderingHintAntiAliasAntiAlias抗鋸齒(無提示,主幹寬度可能不均)中高中
5TextRenderingHintClearTypeGridFitClearTypeGridFitClearType 次像素渲染 + 提示(最高品質)最高較慢

ComboBox 即時切換對比介面

繪製大號 "@" 字符(150pt Arial Black),放大觀察邊緣品質差異。

procedure TForm1.FormPaint(Sender: TObject);
var
  g: TGPGraphics;
  b: TGPBrush;
  font: TGPFont;
begin
  g := TGPGraphics.Create(Canvas.Handle);
  b := TGPSolidBrush.Create(aclRed);
  font := TGPFont.Create('Arial Black', 150);
  g.SetTextRenderingHint(TTextRenderingHint(ComboBox1.ItemIndex));
  g.DrawString('@', -1, font, MakePoint(0.0, -40.0), b);
  font.Free; b.Free; g.Free;
end;

執行效果預覽

文字渲染品質對比

選擇指南

  • 現代 Windows 應用:ClearTypeGridFit (5) - 標準最高品質
  • 跨平台/舊系統:AntiAliasGridFit (3) - 相容性最佳平衡
  • 像素風格/復古:SingleBitPerPixelGridFit (1) - 銳利像素感
  • 高效能/大量文字:SystemDefault (0) - 交由系統決定
  • 避免:SingleBitPerPixel (2)、AntiAlias (4) 缺乏提示,主幹寬度不穩

獨立於 SmoothingMode

文字渲染提示不受 SetSmoothingMode 影響,兩者獨立控制幾何圖形與文字品質。

表單定義檔

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 212
  ClientWidth = 221
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  Position = poDesktopCenter
  OnCreate = FormCreate
  OnPaint = FormPaint
  PixelsPerInch = 96
  TextHeight = 13
  object ComboBox1: TComboBox ... {六個模式項目}
end
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved