Android的:如何获得绘制路径的面积大小? [英] Android: How to get the area size of a drawn path?
本文介绍了Android的:如何获得绘制路径的面积大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题是测量路径的表面积。
我生成一个随机的路径,并绘制在画布上。触摸此closen道路上,我想这个绘制路径的面积大小。
我怎样才能得到这条道路的实际面积大小?
该pathes(形状)看起来像这样的位置:
链接到图片
My problem is to measure the surface area of a path.
I generate a random Path and draw it on a canvas. After touching on this closen path, i want to get the area size of this drawn path.
How can i get the real area size of this path?
The pathes (shapes) looks like this here:
link to the image
推荐答案
我找到了解决办法。我生成路径的区域,并使用RegionIterator使区域内Rects。与此Rects我可以计算路径的整个区域。
I found a solution. I generate a Region from the path and use a RegionIterator to get Rects inside the Region. With this Rects i can calculate the whole area of the path.
private void calculateArea(Region region) {
RegionIterator regionIterator = new RegionIterator(region);
int size = 0; // amount of Rects
float area = 0; // units of area
Rect tmpRect= new Rect();
while (regionIterator.next(tmpRect)) {
size++;
area += tmpRect.width() * tmpRect.height();
}
log.d("Rect amount=" + size);
log.d("Area Size / units of area=" + area);
}
这篇关于Android的:如何获得绘制路径的面积大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文