2016-12-01 64 views
0

我用这个来得到一个路径区域:如何获得路径的精确区域在画布上

RectF rectF = new RectF(); 
Path currentPath = getCurrentPath(); 
currentPath.computeBounds(rectF, true); 
Region region = new Region(); 

这给了我这样一个矩形:

enter image description here

绿色rect是我可以从圈子中获得的区域。

我想通过拖动来移动红圈,所以我需要它的确切边界而不是这个矩形。

这个圆可以从这个方法的中心移动,但我不想要它。我希望它可以从其确切的红点移动。

如何确定确切的边界?

回答

0

我只是通过使用两个区域来解决这个问题。下面是示例代码:

首先,让大圈地区为clickableRegion:

Region clickableRegion = new Region(); 
RectF rectF = new RectF(); 
// bigCirclePath is the red ring 
Path bigCirclePath = getBigCirclePath(); 
bigCirclePath.computeBounds(rectF, true); 
Rect rect = new Rect((int)rectF.left, (int)rectF.top, (int)rectF.right, (int)rectF.bottom); 
// this will get the circle Region 
clickableRegion.setPath(bigCirclePath, new Region(rect)); 

然后,使用类似的代码来获取小圆圈区域为disClickableRegion。小圆圈应该与你的bigcircle具有相同的中心。

定义contains函数;

public boolean conatins(Point p) { 
    if(disClickableRegion.contains(p.x, p.y)) { 
     return false; 
    } 

    return clickableRegion.contains(p.x, p.y); 
}