GdiPlus[34]: IGPGraphicsPath (一)
GdiPlus[34]: IGPGraphicsPath (一)
涂孟超 发表于3年前
GdiPlus[34]: IGPGraphicsPath (一)
  • 发表于 3年前
  • 阅读 4
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 技术升级10大核心产品年终让利>>>   


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

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 测试图:



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 测试图:



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;

 
 
 
 
 

 

 

  

共有 人打赏支持
粉丝 13
博文 2004
码字总数 14107
×
涂孟超
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: