Path.computeBounds 在 Android 上返回不正确的边界(这是平台错误吗?)

pat*_*ats 5 android path

当我使用下面的两种技术计算闭合路径的边界时,我遇到了几个问题。

方法一

    public RectF Truncate(Path path) {

      RectF figureLocationF = new RectF();
      path.computeBounds(figureLocationF, true);
      return   figureLocationF;
    }
Run Code Online (Sandbox Code Playgroud)

方法2

  public RectF Truncate(Path path) {

    RectF figureLocationF = new RectF();
    path.computeBounds(figureLocationF, true);
    Rect figureLocation = new Rect((int)Math.floor(figureLocationF.left), (int)Math.floor(figureLocationF.top)
    ,(int)Math.ceil(figureLocationF.right), (int)Math.ceil(figureLocationF.bottom));


    Rect bounds = new Rect();
    Region region = new Region();
    region.setPath(path, new Region(figureLocation));
    region.getBounds(bounds);

    return new RectF(bounds)
  }
Run Code Online (Sandbox Code Playgroud)

下图显示了结果 在此输入图像描述

方法 1 返回大于路径的边界,这令人困惑,而方法 2 由于小数舍入而截掉了路径的小部分。

我该如何解决这个问题?有没有办法获得精确的边界。

j2e*_*nue -1

我认为没有办法将 false 传递给path.computeBounds(figureLocationF, false);并满足不精确的测量,或者 true 给出精确的测量。如果 android 的精确度不够好,只需计算你自己的界限。这只是方便的方法。在 devleoper 选项“硬件加速渲染”中打开谷歌开发者功能,您可以看到画布重绘的亮点。