其他分享
首页 > 其他分享> > Direct2D (22) : 复合几何对象之 ID2D1TransformedGeometry

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

作者:互联网

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;


效果图:

o_201104062.png

posted on 2011-04-06 15:03  万一  阅读(1260)  评论(0)  编辑  收藏

标签:22,iTransformedGeometry,cvs,iGeometry,Pen,Direct2D,100,ID2D1TransformedGeometry
来源: https://blog.51cto.com/u_14617575/2745403