Direct2D (26) : 获取几何图形的边界



{相关方法}

ID2D1Geometry.GetBounds();        //获取边界矩形

ID2D1Geometry.GetWidenedBounds(); //获取包含画笔区域的边界矩形



测试代码:


uses Direct2D, D2D1;



procedure TForm1.FormPaint(Sender: TObject);

var

  cvs: TDirect2DCanvas;

  iGeometry: ID2D1EllipseGeometry;

  R1,R2: TD2DRectF;

  iBrush: ID2D1SolidColorBrush;

begin

  {几何图形}

  D2DFactory.CreateEllipseGeometry(D2D1Ellipse(D2D1PointF(ClientWidth/2, ClientHeight/2), ClientWidth/4, ClientHeight/4), iGeometry);



  {分别获取两种类型的边界}

  iGeometry.GetBounds(TD2DMatrix3x2F.Identity, R1);

  iGeometry.GetWidenedBounds(25, nil, TD2DMatrix3x2F.Identity, 0, R2);



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

  cvs.BeginDraw;

  cvs.RenderTarget.Clear(D2D1ColorF(clWhite));



  {绘制原图形}

  cvs.RenderTarget.CreateSolidColorBrush(D2D1ColorF(clRed, 0.75), nil, iBrush);

  cvs.RenderTarget.FillGeometry(iGeometry, iBrush);



  {绘制边界}

  iBrush.SetOpacity(1);

  cvs.RenderTarget.DrawRectangle(R1, iBrush);

  cvs.RenderTarget.DrawRectangle(R2, iBrush);



  cvs.EndDraw;

  cvs.Free;

end;



procedure TForm1.FormResize(Sender: TObject);

begin

  Repaint;

end;



效果图:

Direct2D (26) : 获取几何图形的边界

你可能感兴趣的:(DI)