StartCap 和 EndCap 屬性分別用來讀寫兩段的線帽, 測試圖:
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 屬性用來讀寫虛線線帽, 這在實線中沒有效果; 測試圖:
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, 測試圖:
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;