RectF bounds = new RectF();
puteBounds(bounds, true);
Region region = new Region();
region.setPath(path, new Region((int)bounds.left, (int)bounds.top,(int)bounds.right, (int)bounds.bottom));
if (region.contains(x, y)) {
//do sth.
}
Region 表示一个范围,它可以由0个或多个矩形组成。
boolean setPath(Path path, Region clip);
如果最后的结果 region非空,则返回true。
注意clip的传值范围,如果小于path区(如path的外矩形区),可能填充后的region就不太理想
测试发现:如果用该region来进行 canvas.clipRegion(region) 操作,结果不一定正确
kotlin:
private fun pointIsInPath(x: Float, y: Float, path: Path): Boolean {val bounds = RectF()puteBounds(bounds, true)val region = Region()region.setPath(path,Region(Rect(bounds.left.toInt(),bounds.top.toInt(),bounds.right.toInt(),bounds.bottom.toInt())))return region.contains(x.toInt(), y.toInt())}
如果觉得《Android 判断点是否在Path中(含不规则形状的Path)》对你有帮助,请点赞、收藏,并留下你的观点哦!