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;
效果图: