uses Direct2D, D2D1;

procedure TForm1.FormPaint(Sender: TObject);
var
  cvs: TDirect2DCanvas;
  iGeometryGroup: ID2D1GeometryGroup;
  arrGeometry: array[0..3] of ID2D1EllipseGeometry;
  ptCenter: TD2D1Point2F;
  i: Integer;
  rh,rv: Single;
  iFactory: ID2D1Factory;
begin
  ptCenter := D2D1PointF(ClientWidth/2, ClientHeight/2);

  {建立几何对象数组}
  iFactory := D2DFactory();
  rh := ClientWidth / 12;
  rv := ClientHeight / 12;
  for i := 0 to Length(arrGeometry)-1 do
  begin
    iFactory.CreateEllipseGeometry(D2D1Ellipse(ptCenter, rh*(i+1), rv*(i+1)), arrGeometry[i]);
  end;

  {建立 ID2D1GeometryGroup 对象}
  D2DFactory.CreateGeometryGroup(
    D2D1_FILL_MODE_ALTERNATE, //另可选 D2D1_FILL_MODE_WINDING,测试效果图演示了两种填充模式的区别
    @arrGeometry[0],
    Length(arrGeometry),
    iGeometryGroup
  );

  cvs := TDirect2DCanvas.Create(Canvas, ClientRect);
  cvs.BeginDraw;
  cvs.Brush.Color := clWebCornFlowerBlue;
  cvs.FillGeometry(iGeometryGroup);
  cvs.DrawGeometry(iGeometryGroup);
  cvs.EndDraw;
  cvs.Free;
end;

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


效果图:



posted on 2011-04-06 16:02  万一  阅读(1655)  评论(0编辑  收藏  举报