uses Direct2D, D2D1;

procedure TForm1.FormPaint(Sender: TObject);
var
  cvs: TDirect2DCanvas;
  iEllipseGeometry: ID2D1EllipseGeometry;
  iPathGeometry: ID2D1PathGeometry;
  iGeometrySink: ID2D1GeometrySink;
  ptCenter: TPoint;
begin
  ptCenter := Point(ClientWidth div 2, ClientHeight div 2);
  D2DFactory.CreateEllipseGeometry(D2D1Ellipse(ptCenter, ClientWidth/4, ClientHeight/4), iEllipseGeometry);

  D2DFactory.CreatePathGeometry(iPathGeometry);
  iPathGeometry.Open(iGeometrySink);
  iEllipseGeometry.Simplify(
    D2D1_GEOMETRY_SIMPLIFICATION_OPTION_LINES,
    TD2DMatrix3x2F.Identity,
    28, //效果图分别演示了此值是 0、7、28 时的简化效果
    iGeometrySink
  );
  iGeometrySink.Close;

  cvs := TDirect2DCanvas.Create(Canvas, ClientRect);
  cvs.BeginDraw;
  cvs.RenderTarget.Clear(D2D1ColorF(clWhite));
  cvs.DrawGeometry(iPathGeometry);
  cvs.EndDraw;
  cvs.Free;
end;

procedure TForm1.FormResize(Sender: TObject);
begin
  Repaint;
end;


效果图:



posted on 2011-04-07 17:32  万一  阅读(2078)  评论(1编辑  收藏  举报