Delphi GDI+ 学习记录(22): 输出文本<1>

//输出文本var
 g: TGPGraphics;
 sb: TGPSolidBrush;
 fontFamily: TGPFontFamily;
 font: TGPFont;
begin
 g := TGPGraphics.Create(Canvas.Handle);
 sb := TGPSolidBrush.Create(MakeColor(0,0,255));
 fontFamily := TGPFontFamily.Create('宋体');
 font := TGPFont.Create(fontFamily, 48, FontStyleRegular, UnitPixel);
 {参数 3 参考: 文本样式类型表; 参数 4 参考: 坐标单位类型表}
 g.DrawString('Hello World!', -1, font, MakePoint(10.0,10.0), sb);
 {参数 2 是输出文本的长度, -1 表示全部输出;
  参数 4 中的坐标不能用整数, 因为函数指定类型是: TGPRectF}
 sb.Free;
 fontFamily.Free;
 font.Free;
 g.Free;
end;

//简单输出文本var
 g: TGPGraphics;
 sb: TGPSolidBrush;
 font: TGPFont;
begin
 g := TGPGraphics.Create(Canvas.Handle);
 sb := TGPSolidBrush.Create(MakeColor(255,0,0));
 font := TGPFont.Create('宋体',32.0);
 g.DrawString('再见, 2007!', -1, font, MakePoint(10.0,10.0), sb);
 sb.Free;
 font.Free;
 g.Free;
end;

//使用窗体字体属性输出文本var
 g: TGPGraphics;
 sb: TGPSolidBrush;
 font: TGPFont;
begin
 g := TGPGraphics.Create(Canvas.Handle);
 sb := TGPSolidBrush.Create(MakeColor(255,0,0));
 font := TGPFont.Create(Self.Canvas.Handle); //根据窗体的字体属性建立
 g.DrawString('再见, 2007!', -1, font, MakePoint(10.0,10.0), sb);
 sb.Free;
 font.Free;
 g.Free;
end;

//文本呈现质量var
 g : TGPGraphics;
 FontFamily: TGPFontFamily;
 Font: TGPFont;
 sb: TGPSolidBrush;
begin
 g := TGPGraphics.Create(Canvas.Handle);
 FontFamily := TGPFontFamily.Create('Times New Roman');
 Font := TGPFont.Create(FontFamily, 32, FontStyleRegular, UnitPixel);
 sb := TGPSolidBrush.Create(MakeColor(255, 0, 0, 255));
 g.SetTextRenderingHint(TextRenderingHintSingleBitPerPixel);
 g.DrawString('SingleBitPerPixel', -1, font, MakePoint(10.0, 10.0), sb);
 g.SetTextRenderingHint(TextRenderingHintAntiAlias);
 g.DrawString('AntiAlias', -1, font, MakePoint(10.0, 60.0), sb);
 g.Free;
 FontFamily.Free;
 Font.Free;
 sb.Free;
end;

时间: 2024-09-20 16:02:05

Delphi GDI+ 学习记录(22): 输出文本<1>的相关文章

Delphi GDI+ 学习记录(23): 输出文本<2>

//在矩形范围中显示文本var g: TGPGraphics; fontFamily: TGPFontFamily; font: TGPFont; rectF: TGPRectF; p: TGPPen; sb: TGPSolidBrush; str: WideString; begin g := TGPGraphics.Create(Canvas.Handle); fontFamily:= TGPFontFamily.Create('宋体'); font:= TGPFont.Create(fon

Delphi GDI+ 学习记录(24): 输出文本<3>

//获取字体信息 var fontFamily: TGPFontFamily; font: TGPFont; begin fontFamily := TGPFontFamily.Create('宋体'); font := TGPFont.Create(fontFamily, 9, FontStyleRegular, UnitPixel); ShowMessage(FloatToStr(font.GetSize)); {字号大小} ShowMessage(IntToStr(fontFamily.G

Delphi GDI+ 学习记录(28): 图像颜色的数据格式

//指定位图颜色var g,gbit: TGPGraphics; bit1,bit2: TGPBitmap; sb: TGPSolidBrush; begin //Self.Color := clWhite; g := TGPGraphics.Create(Canvas.Handle); sb := TGPSolidBrush.Create(MakeColor(255,0,0)); {画刷为红色} bit1 := TGPBitmap.Create(200, 32, PixelFormat32bp

Delphi GDI+学习记录(21): 颜色

//颜色透明度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:

Delphi GDI+学习记录(4): 画笔对齐

//笔对齐 var g: TGPGraphics; p: TGPPen; sb: TGPSolidBrush; rect: TGPRect; begin g := TGPGraphics.Create(Canvas.Handle); p := TGPPen.Create(MakeColor(255,255,0,0),5); sb := TGPSolidBrush.Create(MakeColor(255,255,255,0)); p.SetAlignment(PenAlignmentCenter

Delphi GDI+学习记录(19): 路径

//绘制与填充路径var g: TGPGraphics; path: TGPGraphicsPath; p: TGPPen; sb: TGPSolidBrush; begin g := TGPGraphics.Create(Canvas.Handle); p := TGPPen.Create(MakeColor(128,255,0,0),4); sb := TGPSolidBrush.Create(MakeColor(128,255,255,0)); path := TGPGraphicsPat

Delphi GDI+学习记录(9): 纹理画刷

//纹理画刷 var g: TGPGraphics; img: TGPImage; tb: TGPTextureBrush; begin g := TGPGraphics.Create(Canvas.Handle); img := TGPImage.Create('c:\temp\small.jpg'); tb := TGPTextureBrush.Create(img); g.FillEllipse(tb, 0, 0, Self.ClientWidth, Self.ClientHeight);

Delphi GDI+学习记录(8): 阴影画刷

//阴影画刷 var g: TGPGraphics; hb: TGPHatchBrush; begin g := TGPGraphics.Create(Canvas.Handle); hb := TGPHatchBrush.Create(HatchStyleHorizontal, aclRed, aclYellow); {参数1是阴影样式; 参数2是前景色; 参数3是背景色, 参数3可选, 默认黑色} g.FillEllipse(hb, 11, 11, 222, 111); hb.Free; g

Delphi GDI+学习记录(3): 虚线画笔

//虚线样式 var g: TGPGraphics; p: TGPPen; begin g := TGPGraphics.Create(Canvas.Handle); p := TGPPen.Create(MakeColor(255,255,0,0),3); g.DrawLine(p, 11, 11, 333, 11); {实线} p.SetDashStyle(DashStyleDashDot); {设置虚线样式} g.DrawLine(p, 11, 33, 333, 33); {绘制任何形状都