• Direct2D (28) : 获取几何图形的面积、线总长度和指定位置的点坐标



    uses Direct2D, D2D1;
    
    procedure TForm1.FormPaint(Sender: TObject);
    var
      cvs: TDirect2DCanvas;
      iEllipseGeometry: ID2D1EllipseGeometry;
      area,length: Single;
      rPointF1,rPointF2: TD2DPoint2f;
      ptCenter: TPoint;
    begin
      ptCenter := Point(ClientWidth div 2, ClientHeight div 2);
      D2DFactory.CreateEllipseGeometry(D2D1Ellipse(ptCenter, ClientWidth/4, ClientHeight/4), iEllipseGeometry);
    
      {获取面积与周长}
      iEllipseGeometry.ComputeArea(TD2DMatrix3x2F.Identity, 0, area);
      iEllipseGeometry.ComputeLength(TD2DMatrix3x2F.Identity, 0, length);
    
      {获取图形的起始处和 1/4 处的点}
      iEllipseGeometry.ComputePointAtLength(0, TD2DMatrix3x2F.Identity, 0, @rPointF1, nil);
      iEllipseGeometry.ComputePointAtLength(length/4, TD2DMatrix3x2F.Identity, 0, @rPointF2, nil);
    
      cvs := TDirect2DCanvas.Create(Canvas, ClientRect);
      cvs.BeginDraw;
      cvs.RenderTarget.Clear(D2D1ColorF(clWhite));
    
      cvs.Font.Size := 9;
      cvs.TextOut(5, 5, Format('面积: %f; 周长: %f', [area, length]));
    
      cvs.DrawGeometry(iEllipseGeometry);
    
      cvs.MoveTo(ptCenter.X, ptCenter.Y);
      cvs.LineTo(Trunc(rPointF1.x), Trunc(rPointF1.y));
      cvs.MoveTo(ptCenter.X, ptCenter.Y);
      cvs.LineTo(Trunc(rPointF2.x), Trunc(rPointF2.y));
    
      cvs.EndDraw;
      cvs.Free;
    end;
    
    procedure TForm1.FormResize(Sender: TObject);
    begin
      Repaint;
    end;
    


    效果图:



  • 相关阅读:
    【leetcode】366.Find Leaves of Binary Tree
    【leetcode】338 .Counting Bits
    【leetcode】419.Battleships in a Board
    【leetcode】544. Output Contest Matches
    【leetcode】496. Next Greater Element I
    ArcEngine创建ShapeFile文件2
    ArcEngine创建ShapeFile文件3
    ArcEngine创建字段集
    ArcEngine创建ShapeFile文件
    ArcEngine创建个人地理数据库
  • 原文地址:https://www.cnblogs.com/del/p/2008119.html
Copyright © 2020-2023  润新知