随笔 - 2146  文章 - 97 评论 - 11758 trackbacks - 253


IGPGraphicsPath.PointCount;   // 点总数
IGPGraphicsPath.PathPoints;   // 点数组, 浮点型
IGPGraphicsPath.PathPointsI;  // 点数组, 整型
IGPGraphicsPath.PathTypes;    // 点类型数组
IGPGraphicsPath.PathData;     // 点与点类型数据, IGPPathData 类型

IGPGraphicsPath.GetLastPoint; // 尾点
IGPGraphicsPath.Reverse;      // 反转点顺序

IGPGraphicsPath.GetBounds();  // 获取包围矩形
{ 关于点类型(它是个 Byte 值) } 0 // 指示此点是图形的起始点 1 // 指示此点是线段的两个终结点之一 3 // 指示此点是立方贝塞尔样条的终结点或控制点 $7 // 用于 3 位掩码运算的, 应该不会实际存在 $20 // 指定此点是一个 Marker(标记) $80 // 指定此点是闭合子路径(图形)中的最后一点 //实际读出的值如果不是这样, 应该是该点有双重身份.

PathPoints、PathTypes、PathData 测试图:



PathPoints、PathTypes、PathData 测试代码:

uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var
  Graphics: IGPGraphics;
  Path: IGPGraphicsPath;
  Brush,BrushPt,BrushText: IGPSolidBrush;
  Pt: TGPPointF;
  PtType: Byte;
  i: Integer;
begin
  Graphics := TGPGraphics.Create(Handle);
  Brush := TGPSolidBrush.Create($FFC0C0C0);
  BrushPt := TGPSolidBrush.Create($80FF0000);
  BrushText := TGPSolidBrush.Create($FF000000);

  Path := TGPGraphicsPath.Create;
  Path.AddString('A', TGPFontFamily.Create('Arial Black'), [], 200, TGPPoint.Create(0,0), nil);
  Path.AddEllipse(210, 76, 100, 144);

  Graphics.FillPath(Brush, Path);
  for i := 0 to Path.PointCount - 1 do
  begin
    Pt := Path.PathPoints[i];
    PtType := Path.PathTypes[i];
    //上两行也可以写作:
    //Pt := Path.PathData.Points[i];
    //PtType := Path.PathData.Types[i];

    Graphics.FillRectangle(BrushPt, Pt.X-3, Pt.Y-3, 6, 6);
    Graphics.DrawString(Format('%x', [PtType]), TGPFont.Create(Canvas.Handle), Pt, BrushText);
  end;
end;


GetLastPoint、Reverse、PathPointsI 测试代码:

uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var
  Path: IGPGraphicsPath;
  PtStart: TGPPoint;
  PtEnd: TGPPointF;
begin
  Path := TGPGraphicsPath.Create;
  Path.AddRectangle(TGPRect.Create(1, 2, 3, 4));

  PtStart := Path.PathPointsI[0];
  PtEnd := Path.GetLastPoint;
  ShowMessageFmt('%d;%d, %g;%g', [PtStart.X, PtStart.Y, PtEnd.X, PtEnd.Y]);
  { (1;2), (1;6) }

  Path.Reverse;
  PtStart := Path.PathPointsI[0];
  PtEnd := Path.GetLastPoint;
  ShowMessageFmt('%d;%d, %g;%g', [PtStart.X, PtStart.Y, PtEnd.X, PtEnd.Y]);
  { (1;6), (1;2) }
end;


GetBounds 测试图:



GetBounds 测试代码:

uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var
  Graphics: IGPGraphics;
  Path: IGPGraphicsPath;
  Pen: IGPPen;
  Rect: TGPRect;
begin
  Graphics := TGPGraphics.Create(Handle);
  Pen := TGPPen.Create($FFFF0000, 2);
  Path := TGPGraphicsPath.Create;
  Path.AddLine(20, 20, 150, 100);

  Graphics.DrawPath(Pen, Path);

  Pen.Width := 1;
  Pen.Color := $FFC0C0C0;
  Path.GetBounds(Rect);
  Graphics.DrawRectangle(Pen, Rect);
end;

posted on 2009-12-17 16:40 万一 阅读(...) 评论(...) 编辑 收藏