• 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;
    

  • 相关阅读:
    Tree UVA
    stringstream的使用
    Trees on the level UVA
    strchr和strstr函数
    sscanf的用法
    Dropping Balls UVA
    Boxes in a Line UVA
    Broken Keyboard (a.k.a. Beiju Text) UVA
    Matrix Chain Multiplication (堆栈)
    出栈次序
  • 原文地址:https://www.cnblogs.com/del/p/1626333.html
Copyright © 2020-2023  润新知