Delphi GDI+ 文本输出

unit Unit1;

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

type
TForm1 = class(TForm)
CheckListBox1: TCheckListBox;
procedure FormPaint(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure CheckListBox1Click(Sender: TObject);
end;

var
Form1: TForm1;

implementation
{$R *.dfm}
uses GDIPOBJ, GDIPAPI;

var fs: Integer;

procedure TForm1.CheckListBox1Click(Sender: TObject);
const
fsArr: array[0..5] of Integer = (FontStyleRegular,
FontStyleBold,
FontStyleItalic,
FontStyleBoldItalic,
FontStyleUnderline,
FontStyleStrikeout);
var
i: Integer;
begin
fs := 0;
for i := 0 to CheckListBox1.Items.Count - 1 do
if CheckListBox1.Checked[i] then
fs := fs or fsArr[i];
Repaint;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
CheckListBox1.Align := alLeft;
CheckListBox1.Items.CommaText := 'FontStyleRegular,' +
'FontStyleBold,' +
'FontStyleItalic,' +
'FontStyleBoldItalic,' +
'FontStyleUnderline,' +
'FontStyleStrikeout';
CheckListBox1.Checked[0] := True;
end;

procedure TForm1.FormPaint(Sender: TObject);
var
g: TGPGraphics;
sb: TGPSolidBrush;
font: TGPFont;
begin
g := TGPGraphics.Create(Canvas.Handle);
sb := TGPSolidBrush.Create(aclRed);

font := TGPFont.Create('微软雅黑', 50, fs);
g.DrawString('Delphi', -1, font, MakePoint(CheckListBox1.Width + 0.0, 0), sb);

font.Free;
sb.Free;
g.Free;
end;

end.

FontStyle = Integer;
const
FontStyleRegular = Integer(0);
 {普通文本}
FontStyleBold = Integer(1);
 {加粗文本}
FontStyleItalic = Integer(2);
 {倾斜文本}
FontStyleBoldItalic = Integer(3);
 {加粗并倾斜文本}
FontStyleUnderline = Integer(4);
 {带下划线的文本}
FontStyleStrikeout = Integer(8);
 {中间有直线通过的文本}
Type
TFontStyle = FontStyle;


文本样式类型表:
Delphi 微软 说明 FontStyleBold Bold 加粗文本。 FontStyleItalic Italic 倾斜文本。 FontStyleRegular Regular 普通文本。 FontStyleStrikeout Strikeout 中间有直线通过的文本。 FontStyleUnderline Underline 带下划线的文本。
坐标单位类型表:
Delphi 微软 说明 UnitDisplay Display 指定显示设备的度量单位。通常,视频显示使用的单位是像素;打印机使用的单位是 1/100 英寸。 UnitDocument Document 将文档单位(1/300 英寸)指定为度量单位。 UnitInch Inch 将英寸指定为度量单位。 UnitMillimeter Millimeter 将毫米指定为度量单位。 UnitPixel Pixel 将设备像素指定为度量单位。 UnitPoint Point 将打印机点(1/72 英寸)指定为度量单位。 UnitWorld World 将世界坐标系单位指定为度量单位。
文本呈现质量模式:
Delphi 微软 说明 TextRenderingHintAntiAlias AntiAlias 在无提示的情况下使用每个字符的消除锯齿效果标志符号位图来绘制字符。由于采用了 AntiAlias,质量会得到改善。由于关闭了提示,主干宽度差可能会比较明显。 TextRenderingHintAntiAliasGridFit AntiAliasGridFit 在有提示的情况下使用每个字符的消除锯齿效果标志符号位图来绘制字符。由于采用了 AntiAlias,质量会得到大大改善,但同时会增加性能成本。 TextRenderingHintClearTypeGridFit ClearTypeGridFit 在有提示的情况下使用每个字符的标志符号 ClearType 位图来绘制字符。这是质量最高的设置。用于利用 ClearType 字体功能。 TextRenderingHintSingleBitPerPixel SingleBitPerPixel 使用每个字符的标志符号位图来绘制字符。不使用提示。 TextRenderingHintSingleBitPerPixelGridFit SingleBitPerPixelGridFit 使用每个字符的标志符号位图来绘制字符。提示用于改善字符在主干和弯曲部分的外观。 TextRenderingHintSystemDefault SystemDefault 在有系统默认呈现提示的情况下使用每个字符的标志符号位图来绘制字符。将采用用户为系统选择的任何字体修匀设置来绘制文本。

//颜色透明度var g: TGPGraphics;
 sb: TGPSolidBrush;
begin g := TGPGraphics.Create(Canvas.Handle);
 sb := TGPSolidBrush.Create(MakeColor(128,255,0,0));
 {128表示半透明} g.FillRectangle(sb,10,10,100,100);
 sb.Free;
 g.Free;
end;


--------------------------------------------------------------------------------

//使用 GDI+ 的颜色类型var g: TGPGraphics;
 sb: TGPSolidBrush;
 color: TGPColor;
 {其实颜色是 DWORD 类型的}begin g := TGPGraphics.Create(Canvas.Handle);
 color := aclRed;
 sb := TGPSolidBrush.Create(color);
 g.FillRectangle(sb,10,10,100,100);
 sb.Free;
 g.Free;
end;


--------------------------------------------------------------------------------

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值