再学 GDI+[45]: 文本输出 文本呈现质量

本例效果图:



代码文件:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    procedure FormPaint(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses GDIPOBJ, GDIPAPI, TypInfo;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  for i := 0 to 5 do
    ComboBox1.Items.Add(GetEnumName(TypeInfo(TTextRenderingHint), i));
  ComboBox1.ItemIndex := 0;
end;

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;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
  Repaint;
end;

end.

窗体文件:
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
    Left = 8
    Top = 3
    Width = 207
    Height = 21
    ItemHeight = 13
    TabOrder = 0
    Text = 'ComboBox1'
    OnChange = ComboBox1Change
  end
end

文本呈现质量模式:

Delphi 微软 说明
TextRenderingHintSystemDefault SystemDefault 在有系统默认呈现提示的情况下使用每个字符的标志符号位图来绘制字符。将采用用户为系统选择的任何字体修匀设置来绘制文本。
TextRenderingHintSingleBitPerPixelGridFit  SingleBitPerPixelGridFit  使用每个字符的标志符号位图来绘制字符。提示用于改善字符在主干和弯曲部分的外观。
TextRenderingHintSingleBitPerPixel SingleBitPerPixel 使用每个字符的标志符号位图来绘制字符。不使用提示。
TextRenderingHintAntiAliasGridFit AntiAliasGridFit 在有提示的情况下使用每个字符的消除锯齿效果标志符号位图来绘制字符。由于采用了 AntiAlias,质量会得到大大改善,但同时会增加性能成本。
TextRenderingHintAntiAlias AntiAlias 在无提示的情况下使用每个字符的消除锯齿效果标志符号位图来绘制字符。由于采用了 AntiAlias,质量会得到改善。由于关闭了提示,主干宽度差可能会比较明显。
TextRenderingHintClearTypeGridFit ClearTypeGridFit 在有提示的情况下使用每个字符的标志符号 ClearType 位图来绘制字符。这是质量最高的设置。用于利用 ClearType 字体功能。


原文地址:https://www.cnblogs.com/del/p/1224057.html