Search code examples
androidpathregion

Calculating the total area of a Region


I would like to be able to know the total area covered by a region (e.g. a double integral over this said area). I cannot find any method for that, and I wonder will I have to go pixel-by-pixel. Thanks in advance!


Solution

  • You should be able to use a RegionIterator and sum the areas of the rectangles returned.

    Reasoning: The Andriod docs imply that when boolean ops are done on regions, the result region is a new set of non-overlapping rectangles with the desired union. In other words, A - B, where A and B are rectangles, may produce 0, 1, 2, 3, or 4 rectangles as a result.

    I have not tested, but the source at the Android xRef site shows that a validated region consists of rectangles with no overlaps.