其他分享
首页 > 其他分享> > Direct2D (26) : 获取几何图形的边界

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

作者:互联网

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;


效果图:

o_201104072.png

posted on 2011-04-07 12:24  万一  阅读(1449)  评论(0)  编辑  收藏

标签:26,几何图形,iGeometry,cvs,RenderTarget,Direct2D,边界,iBrush
来源: https://blog.51cto.com/u_14617575/2745399