GdiPlus[31]: IGPPen: 自定义线帽


自定义线帽可以通过两个接口: IGPCustomLineCap、IGPAdjustableArrowCap.

后者继承与前者, 专用于修改箭头线帽.

IGPAdjustableArrowCap 测试效果图:

26153903_Fu2e.png

IGPAdjustableArrowCap 测试代码:

uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var
  Graphics: IGPGraphics;
  Pen: IGPPen;
  Cap1,Cap2: IGPAdjustableArrowCap;
begin
  Graphics := TGPGraphics.Create(Handle);
  Pen := TGPPen.Create($FFDC143C, 4);

  Cap1 := TGPAdjustableArrowCap.Create(4, 4);
  Cap2 := TGPAdjustableArrowCap.Create(4, 4, False);
  Pen.CustomStartCap := Cap1;
  Pen.CustomEndCap := Cap2;
  Graphics.DrawLine(Pen, 30, 30, 250, 30);

  Cap1 := TGPAdjustableArrowCap.Create(4, 8);
  Cap2 := TGPAdjustableArrowCap.Create(4, 8, False);
  Pen.CustomStartCap := Cap1;
  Pen.CustomEndCap := Cap2;
  Graphics.DrawLine(Pen, 30, 80, 250, 80);
end;

 
 
 
 
 

 

 

  

IGPCustomLineCap 测试效果图:

26153903_sVhq.png

IGPCustomLineCap 测试代码:

uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
const
  pts: array[0..3] of TGPPoint = ((X:-4; Y:0),(X:0; Y:-4),(X:4; Y:0),(X:0; Y:8));
var
  Graphics: IGPGraphics;
  Pen: IGPPen;
  Path1,Path2: IGPGraphicsPath;
  Cap1,Cap2: IGPCustomLineCap;
  Pt1,Pt2: TGPPoint;
begin
  Graphics := TGPGraphics.Create(Handle);

  Path1 := TGPGraphicsPath.Create;
  Path1.AddEllipse(TGPRect.Create(-3, -3, 6, 6));

  Path2 := TGPGraphicsPath.Create;
  Path2.AddPolygon(pts);

  Pt1.Initialize(50, 30);
  Pt2.Initialize(50, 150);

  Pen := TGPPen.Create($FF8B0000, 3);

  //
  Cap1 := TGPCustomLineCap.Create(nil, Path1);
  Cap2 := TGPCustomLineCap.Create(nil, Path2);
  Pen.CustomStartCap := Cap1;
  Pen.CustomEndCap := Cap2;
  Graphics.DrawLine(Pen, Pt1, Pt2);
  Graphics.TranslateTransform(Pt1.X, 0);

  //
  Cap1 := TGPCustomLineCap.Create(nil, Path1, LineCapFlat, 3);
  Cap2 := TGPCustomLineCap.Create(nil, Path2, LineCapFlat, 4);
  Pen.CustomStartCap := Cap1;
  Pen.CustomEndCap := Cap2;
  Graphics.DrawLine(Pen, Pt1, Pt2);
  Graphics.TranslateTransform(Pt1.X, 0);

  //注意: 使用填充路径时, 对构建路径的参数要求比较古怪...
  Cap1 := TGPCustomLineCap.Create(Path1, nil);
  Cap2 := TGPCustomLineCap.Create(Path2, nil);
  Pen.CustomStartCap := Cap1;
  Pen.CustomEndCap := Cap2;
  Graphics.DrawLine(Pen, Pt1, Pt2);
  Graphics.TranslateTransform(Pt1.X, 0);

  //
  Cap1 := TGPCustomLineCap.Create(Path1, nil);
  Cap2 := TGPCustomLineCap.Create(Path2, nil);
  Cap1.WidthScale := 0.75;
  Cap2.WidthScale := 1.3;
  Pen.CustomStartCap := Cap1;
  Pen.CustomEndCap := Cap2;
  Graphics.DrawLine(Pen, Pt1, Pt2);
end;

 
 
 
 
 

 

 

  

转载于:https://my.oschina.net/hermer/blog/320745

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值