GdiPlus[34]: IGPGraphicsPath (一)


路径是一组图形命令, 它能容纳所有基本图形和文本、子路径:

IGPGraphicsPath.AddLine();
IGPGraphicsPath.AddLines();
IGPGraphicsPath.AddArc();
IGPGraphicsPath.AddBezier();
IGPGraphicsPath.AddBeziers();
IGPGraphicsPath.AddCurve();
IGPGraphicsPath.AddClosedCurve();
IGPGraphicsPath.AddRectangle();
IGPGraphicsPath.AddRectangles();
IGPGraphicsPath.AddEllipse();
IGPGraphicsPath.AddPie();
IGPGraphicsPath.AddPolygon();
IGPGraphicsPath.AddPath();
IGPGraphicsPath.AddString();

{ 本页示例相关命令 }
IGPGraphics.DrawPath            // 绘制路径
IGPGraphics.FillPath            // 填充路径
IGPGraphicsPath.FillMode        // 路径填充模式

IGPGraphicsPath.StartFigure     // 开始一个新的图形, 并不关闭之前的图形
IGPGraphicsPath.CloseFigure     // 关闭当前图形, 并开始新图形
IGPGraphicsPath.CloseAllFigures // 关闭之前所有开放图形, 并开始新图形
IGPGraphicsPath.Reset           // 重置路径

 
 
 
 
 

 

 

  

FillPath、DrawPath 测试图:

26153808_jDnd.png

FillPath、DrawPath 测试代码:

uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var
  Graphics: IGPGraphics;
  Path: IGPGraphicsPath;
  Pen: IGPPen;
  Brush: IGPBrush;
begin
  Path := TGPGraphicsPath.Create;
  Path.AddRectangle(TGPRect.Create(20, 20, 96, 60));
  Path.AddEllipse(TGPRect.Create(92, 20, 120, 60));

  Graphics := TGPGraphics.Create(Handle);
  Pen := TGPPen.Create($FFFF0000, 2);
  Brush := TGPSolidBrush.Create($FFFFD700);

  Graphics.DrawPath(Pen, Path);
  Graphics.TranslateTransform(0, 80);

  Graphics.FillPath(Brush, Path);
  Graphics.TranslateTransform(0, 80);

  Graphics.FillPath(Brush, Path);
  Graphics.DrawPath(Pen, Path);
  Graphics.TranslateTransform(0, 80);

  //填充模式有两种, 默认的是 FillModeAlternate; 可以在建立路径时指定填充模式
  Path.FillMode := FillModeWinding;
  Graphics.FillPath(Brush, Path);
  Graphics.DrawPath(Pen, Path);
  Graphics.TranslateTransform(0, 80);
end;

 
 
 
 
 

 

 

  

StartFigure、CloseFigure、CloseAllFigures、Reset 测试图:

26153808_IcL7.png

StartFigure、CloseFigure、CloseAllFigures、Reset 测试代码:

uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
const
  Pts1: array[0..2] of TGPPoint = ((X:0;   Y:30), (X:30;  Y:0), (X:60;  Y:30));
  Pts2: array[0..2] of TGPPoint = ((X:80;  Y:30), (X:110; Y:0), (X:140; Y:30));
  Pts3: array[0..2] of TGPPoint = ((X:160; Y:30), (X:190; Y:0), (X:220; Y:30));
var
  Graphics: IGPGraphics;
  Path: IGPGraphicsPath;
  Pen: IGPPen;
  Brush: IGPBrush;
begin
  Graphics := TGPGraphics.Create(Handle);
  Pen := TGPPen.Create($FFFF0000, 2);
  Brush := TGPSolidBrush.Create($FFD0D0D0);
  Path := TGPGraphicsPath.Create;

  //
  Path.AddLines(Pts1);
  Path.AddLines(Pts2);
  Path.AddLines(Pts3);
  Graphics.FillPath(Brush, Path);
  Graphics.DrawPath(Pen, Path);
  Graphics.TranslateTransform(0, 50);

  //
  Path.Reset;
  Path.StartFigure;
    Path.AddLines(Pts1);
  Path.StartFigure;
    Path.AddLines(Pts2);
  Path.StartFigure;
    Path.AddLines(Pts3);

  Graphics.FillPath(Brush, Path);
  Graphics.DrawPath(Pen, Path);
  Graphics.TranslateTransform(0, 50);

  //
  Path.Reset;
  Path.StartFigure;
    Path.AddLines(Pts1);
  Path.StartFigure;
    Path.AddLines(Pts2);
  Path.StartFigure;
    Path.AddLines(Pts3);
  Path.CloseFigure;
  Graphics.FillPath(Brush, Path);
  Graphics.DrawPath(Pen, Path);
  Graphics.TranslateTransform(0, 50);

  //
  Path.Reset;
  Path.StartFigure;
    Path.AddLines(Pts1);
  Path.StartFigure;
    Path.AddLines(Pts2);
  Path.StartFigure;
    Path.AddLines(Pts3);
  Path.CloseAllFigures;
  Graphics.FillPath(Brush, Path);
  Graphics.DrawPath(Pen, Path);
  Graphics.TranslateTransform(0, 50);

  //
  Path.Reset;
  Path.StartFigure;
    Path.AddLines(Pts1);
    Path.AddLines(Pts2);
    Path.AddLines(Pts3);
  Path.CloseFigure;
  Graphics.FillPath(Brush, Path);
  Graphics.DrawPath(Pen, Path);
end;

 
 
 
 
 

 

 

  

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值