2

Android 区域 ( android.graphics.Region ) 是否总是有一个矩形区域,还是可以是多边形或圆形(弯曲)?

实际上,我必须对多个区域进行一些Region.Op.UNION操作Region.Op.INTERSECTION。我想知道Ultimate Output Region的形状,是否还有矩形区域?

4

2 回答 2

1

它可以是复杂的 ( isComplex()),即它由多个矩形组成。不确定“弯曲”是什么意思,但它可以是多边形的。如果我理解正确,您可以使用getBoundaryPath()来获取描述结果形状的路径。

于 2013-02-12T13:42:34.577 回答
1

文档中的任何内容都不会导致人们得出结论,区域可以不是矩形,它是由矩形、x、y 坐标加上宽度和高度构成的,或者由另一个区域构成。

可以从路径描述矩形,因此 getBoundaryPath() 不一定得出非矩形是可能的结论。可以替代地暗示包含矩形边界。

isComplex() 属性仅表示它由多个矩形组成。它们是否都被一个外部定义的矩形所束缚?如果是这样,我们如何将它们分开?在没有足够的文档的情况下,没有实验就无法判断:

以下代码描述了一条路径并创建了一个多边形区域。我们从任意数量的坐标对的数组开始。然后:

    //describe a path corresponding to the transformed polygon
    Path transformPath;
    transformPath = new Path();

    //starting point
    transformPath.moveTo(getTransformedPolygon()[0], getTransformedPolygon()[1]);

    //draw a line from one point to the next
    for(int i = 2; i < arrayCoordinates.length; i = i + 2)
    {
        transformPath.lineTo(arrayCoordinates[i], arrayCoordinates[i + 1]);
    }

    //then end at the starting point to close the polygon
    transformPath.lineTo(arrayCoordinates[0], arrayCoordinates[1]);

    //describe a region (clip area) corresponding to the game area (my example is a game app)
    Region clip = new Region(0, 0, gameSurfaceWidth, gameSurfaceHeight);

    //describe a region corresponding to the transformed polygon path
    transformRegion = new Region();
    transformRegion.setPath(transformPath, clip);

如果将区域显示为字符串,您将看到构成多边形的几对坐标。

于 2017-08-29T21:47:11.910 回答