Direct2D (22) : 复合几何对象之 ID2D1TransformedGeometry


复合几何对象包括 ID2D1GeometryGroup 和 ID2D1TransformedGeometry,它们都继承自 ID2D1Geometry。

ID2D1TransformedGeometry 只是包含了 2D 变换的 ID2D1Geometry。



uses Direct2D, D2D1;



procedure TForm1.FormPaint(Sender: TObject);

var

  cvs: TDirect2DCanvas;

  iTransformedGeometry: ID2D1TransformedGeometry;

  iRectangleGeometry: ID2D1RectangleGeometry;

  iGeometry: ID2D1Geometry;

  R: TRect;

begin

  {建立一个矩形的 ID2D1Geometry}

  R := Bounds((ClientWidth-100) div 2, (ClientHeight-100) div 2, 100, 100);

  D2DFactory.CreateRectangleGeometry(R, iRectangleGeometry);



  {建立 ID2D1TransformedGeometry}

  D2DFactory.CreateTransformedGeometry(

    iRectangleGeometry,

    TD2DMatrix3x2F.Rotation(45, ClientWidth/2, ClientHeight/2),

    iTransformedGeometry

  );



  cvs := TDirect2DCanvas.Create(Canvas, ClientRect);

  cvs.BeginDraw;



  {绘制原始矩形}

  cvs.Pen.Color := clGreen;

  cvs.Pen.Width := 11;

  cvs.DrawGeometry(iRectangleGeometry);



  {绘制 ID2D1TransformedGeometry}

  cvs.Brush.Color := clGreen;

  cvs.FillGeometry(iTransformedGeometry);



  {绘制从 ID2D1TransformedGeometry 再次获取的 iGeometry}

  cvs.Pen.Color := clWhite;

  cvs.Pen.Width := 1;

  iTransformedGeometry.GetSourceGeometry(iGeometry);

  cvs.DrawGeometry(iGeometry);



  cvs.EndDraw;

  cvs.Free;

end;



procedure TForm1.FormResize(Sender: TObject);

begin

  Repaint;

end;



效果图:

Direct2D (22) : 复合几何对象之 ID2D1TransformedGeometry

你可能感兴趣的:(transform)