uses Direct2D, D2D1;

procedure TForm1.FormPaint(Sender: TObject);
var
  cvs: TDirect2DCanvas;
  iEllipseGeometry: ID2D1EllipseGeometry;
  iTransformedGeometrys: array[0..7] of ID2D1TransformedGeometry;
  iGeometryGroup: ID2D1GeometryGroup;
  iGeometrySink: ID2D1GeometrySink;
  iPathGeometry: ID2D1PathGeometry;
  ptCenter: TD2DPoint2f;
  i: Integer;
begin
  {建立几何对象}
  ptCenter := D2D1PointF(ClientWidth/2, ClientHeight/2);
  for i := 0 to 7 do
  begin
    D2DFactory.CreateEllipseGeometry(D2D1Ellipse(ptCenter, 100, 25), iEllipseGeometry);
    D2DFactory.CreateTransformedGeometry(iEllipseGeometry, TD2DMatrix3x2F.Rotation(360/8*i, ptCenter), iTransformedGeometrys[i]);
  end;
  D2DFactory.CreateGeometryGroup(D2D1_FILL_MODE_WINDING, @iTransformedGeometrys[0], 8, iGeometryGroup);

  {获取轮廓到 iPathGeometry}
  D2DFactory.CreatePathGeometry(iPathGeometry);
  iPathGeometry.Open(iGeometrySink);
  iGeometryGroup.Outline(TD2DMatrix3x2F.Identity, 0, iGeometrySink);
  iGeometrySink.Close;

  {绘制图形与轮廓}
  cvs := TDirect2DCanvas.Create(Canvas, ClientRect);
  cvs.BeginDraw;
  cvs.RenderTarget.Clear(D2D1ColorF(clWhite));

  cvs.Brush.Color := clYellow;
  cvs.Pen.Color := clRed;
  cvs.FillGeometry(iGeometryGroup);
  cvs.DrawGeometry(iGeometryGroup);

  cvs.Pen.Brush.Handle.SetOpacity(0.5);
  cvs.Pen.Width := 11;
  cvs.DrawGeometry(iPathGeometry);

  cvs.EndDraw;
  cvs.Free;
end;

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


效果图:



posted on 2011-04-07 15:16  万一  阅读(1989)  评论(0编辑  收藏  举报