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);  {绘制任何形状都是可以的}
 p.Free;
 g.Free;
end;
//自定义虚线样式
var
 g: TGPGraphics;
 p: TGPPen;
const
 dash: array[0..3] of Single = (5,2,15,10); {虚线样式数组, 数组维数大小任意}
begin
 g := TGPGraphics.Create(Canvas.Handle);
 p := TGPPen.Create(MakeColor(255,255,0,0),3);
 g.DrawLine(p, 11, 11, 333, 11);
 p.SetDashPattern(@dash, Length(dash)); {设置虚线}
 g.DrawLine(p, 11, 33, 333, 33);
 p.Free;
 g.Free;
end;

虚线样式表:

Delphi 微软 说明
DashStyleCustom Custom 指定用户定义的自定义划线段样式。
DashStyleDash Dash 指定由划线段组成的直线。
DashStyleDashDot DashDot 指定由重复的划线点图案构成的直线。
DashStyleDashDotDot DashDotDot 指定由重复的划线点点图案构成的直线。
DashStyleDot Dot 指定由点构成的直线。
DashStyleSolid Solid 指定实线。
时间: 2025-01-21 06:21:43

Delphi GDI+学习记录(3): 虚线画笔的相关文章

Delphi GDI+学习记录(5): 复合画笔

//复合画笔 var g: TGPGraphics; p: TGPPen; arr: array[0..9] of Single; {10 个元素可以分成 5 条线, 每条线需要起点和终点} begin g := TGPGraphics.Create(Canvas.Handle); p := TGPPen.Create(MakeColor(255,255,0,0),100); {笔宽定为 100 好算帐} arr[0] := 0.00; {第一条线起点} arr[1] := 0.01; {第一条

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+学习记录(6): 使用画刷建立画笔

//使用画刷建立画笔 var g: TGPGraphics; img: TGPImage; tb: TGPTextureBrush; p: TGPPen; begin g := TGPGraphics.Create(Canvas.Handle); img := TGPImage.Create('c:\temp\small.jpg'); tb := TGPTextureBrush.Create(img); p := TGPPen.Create(tb,36); {参数 1 是画刷; 参数 2 是笔宽

Delphi GDI+学习记录(2): 画笔线帽

//线帽 var g: TGPGraphics; p: TGPPen; begin g := TGPGraphics.Create(Canvas.Handle); p:= TGPPen.Create(aclBlue, 8); p.SetStartCap(LineCapArrowAnchor); {起点线帽} p.SetEndCap(LineCapRoundAnchor); {终点线帽} g.DrawLine(p, 20, 20, 300, 175); p.Free; g.Free; end; 线

Delphi GDI+学习记录(1) 画笔

//画笔 var g: TGPGraphics; p: TGPPen; begin g := TGPGraphics.Create(Canvas.Handle); p := TGPPen.Create(aclRed, 2); {参数1颜色; 参数2是笔宽, 笔宽是可选, 默认 1} g.DrawEllipse(p, 11, 11, 222, 111); p.Free; g.Free; end; //设置笔宽与颜色 var g: TGPGraphics; p: TGPPen; begin 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+学习记录(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+学习记录(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