這是我沒有和它似乎工作:
RectF rectF = new RectF();
path.computeBounds(rectF, true);
region = new Region();
region.setPath(path, new Region((int) rectF.left, (int) rectF.top, (int) rectF.right, (int) rectF.bottom));
現在你可以使用region.contains(x,y)
方法。
Point point = new Point();
mapView.getProjection().toPixels(geoPoint, point);
if (region.contains(point.x, point.y)) {
// Within the path.
}
**更新在2010年6月7日** 的region.setPath方法將導致我的應用程序崩潰(沒有警告消息)如果rectF太大。這裏是我的解決方案:
// Get the screen rect. If this intersects with the path's rect
// then lets display this zone. The rectF will become the
// intersection of the two rects. This will decrease the size therefor no more crashes.
Rect drawableRect = new Rect();
mapView.getDrawingRect(drawableRect);
if (rectF.intersects(drawableRect.left, drawableRect.top, drawableRect.right, drawableRect.bottom)) {
// ... Display Zone.
}
啊,好吧,我喜歡它。無論如何,額外的記憶沒有做任何有用的事! 我曾經遇到過的一個問題是,ALPHA_8不會再給我任何東西,只有0返回使用getPixel。我不得不放棄並使用ARGB_8888。我發現幾乎沒有關於ALPHA_8格式的文檔以及它的侷限性,但它確實在我這裏不起作用。 謝謝Brian。 – 2010-04-08 06:32:40
鍛鍊記憶!整個Skia Android 2D框架都沒有記錄。對4倍內存需求感到遺憾,但至少Android屏幕非常小。 – Brian 2010-04-08 07:20:15
@TomSeago嗨,我得到了同樣的問題,我也必須使用ARGB_8888,如果使用ALPHA_8,沒有任何回報! – John 2014-08-31 09:59:15