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;
    

  • 相关阅读:
    node
    github
    [模块] pdf转图片-pdf2image
    python 15 自定义模块 随机数 时间模块
    python 14 装饰器
    python 13 内置函数II 匿名函数 闭包
    python 12 生成器 列表推导式 内置函数I
    python 11 函数名 迭代器
    python 10 形参角度 名称空间 加载顺序
    python 09 函数参数初识
  • 原文地址:https://www.cnblogs.com/del/p/1626333.html
Copyright © 2011-2022 走看看