StartCap 和 EndCap 属性分别用来读写两段的线帽, 测试图:
![o_09121601.png](https://i-blog.csdnimg.cn/blog_migrate/56088e0742844d495fcebf4d332baa5d.png)
StartCap 和 EndCap 测试代码:
uses GdiPlus; procedure TForm1.FormPaint(Sender: TObject); const CapArr: array[0..8] of Byte = (0, 1, 2, 3, $10, $11, $12, $13, $14); var Graphics: IGPGraphics; Pen: IGPPen; Pt1,Pt2: TGPPoint; i: Integer; begin Pt1.Initialize(20, 20); Pt2.Initialize(200, 20); Graphics := TGPGraphics.Create(Handle); Pen := TGPPen.Create($FF2E8B57, 11); for i := 0 to Length(CapArr) - 1 do begin Pen.StartCap := TGPLineCap(CapArr[i]); Pen.EndCap := Pen.StartCap; Graphics.DrawLine(Pen, Pt1, Pt2); Graphics.TranslateTransform(0, Pt1.Y * 1.5); end; end;
DashCap 属性用来读写虚线线帽, 这在实线中没有效果; 测试图:
![o_09121602.png](https://i-blog.csdnimg.cn/blog_migrate/02db0c1c434010e6cade3a34bed27282.png)
DashCap 测试代码:
uses GdiPlus; procedure TForm1.FormPaint(Sender: TObject); var Graphics: IGPGraphics; Pen: IGPPen; Pt1,Pt2: TGPPoint; begin Pt1.Initialize(20, 20); Pt2.Initialize(240, 20); Graphics := TGPGraphics.Create(Handle); Pen := TGPPen.Create($FF4169E1, 11); Pen.DashStyle := DashStyleDashDot; Pen.DashCap := DashCapFlat; Graphics.DrawLine(Pen, Pt1, Pt2); Graphics.TranslateTransform(0, Pt1.Y * 1.5); Pen.DashCap := DashCapRound; Graphics.DrawLine(Pen, Pt1, Pt2); Graphics.TranslateTransform(0, Pt1.Y * 1.5); Pen.DashCap := DashCapTriangle; Graphics.DrawLine(Pen, Pt1, Pt2); end;
可通过 SetLineCap 方法一起设定 StartCap、EndCap、DashCap, 测试图:
![o_09121603.png](https://i-blog.csdnimg.cn/blog_migrate/2b823227a9873270803b8175d1951385.png)
SetLineCap 测试代码:
uses GdiPlus; procedure TForm1.FormPaint(Sender: TObject); var Graphics: IGPGraphics; Pen: IGPPen; begin Graphics := TGPGraphics.Create(Handle); Pen := TGPPen.Create($FFC71585, 11); Pen.DashStyle := DashStyleDashDot; Pen.SetLineCap(LineCapRoundAnchor, LineCapArrowAnchor, DashCapTriangle); Graphics.DrawLine(Pen, 20, 30, 300, 30); end;