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;


posted on 2009-12-16 12:21  万一  阅读(2299)  评论(0编辑  收藏  举报