2013-02-12 34 views
2

Android區域(android.graphics.Region)總是有矩形區域,還是可以是多邊形或圓形(彎曲)?是android區域總是一個矩形區域,或者它可能是多邊形或曲線?

其實我必須做一些Region.Op.UNIONRegion.Op.INTERSECTION操作與多個地區。 我想知道Ultimate Output Region的形狀,它是否還有矩形區域?

+2

我會假設不是由於'公共布爾isRect()'方法有點多餘,如果它總是一個矩形。文檔中似乎有很多涉及可包含弧線的路徑的操作。 – rich200313 2013-02-12 13:34:38

回答

1

它可能很複雜(isComplex()),即它由多個矩形組成。不知道「彎曲」是什麼意思,但它可以是多邊形。如果我理解正確,則可以使用getBoundaryPath()來獲取描述所得形狀的路徑。

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); 

如果將該區域顯示爲字符串,則會看到構成多邊形形狀的幾對座標。

相關問題