zoukankan      html  css  js  c++  java
  • 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 测试图:



    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;
    

  • 相关阅读:
    设计模式之原型模式
    【转载】 吵翻了!这张图里到底是人还是狗?心理学家这样说
    【转载】 DeepMind 提出元梯度强化学习算法,显著提高大规模深度强化学习应用的性能
    ubuntu18.04 安装wine64出现错误: X 64-bit development files not found.
    ubuntu18.04 源码方式安装wine , 警告,libxrender 64-bit development files not found, XRender won't be supported.
    【转载】 信息如何像零食、金钱一样掌控你的大脑
    图像处理算法 之 滤波 模糊(基于OpenCV)
    图像处理之FPN校正
    ISP-黑电平校正(BLC)
    ISP基础(0y):图像传感器
  • 原文地址:https://www.cnblogs.com/del/p/1626333.html
Copyright © 2011-2022 走看看