在地图覆盖层上给定一组点绘制一个空多边形(Android 2.1)

发布于 2024-09-01 04:01:31 字数 610 浏览 7 评论 0原文

我设置了 n 个点,我想使用这些点绘制一个 n 边多边形。

我尝试使用 android.graphics.path (请参见下文)。

Path path = new Path();
Vertex currVtx;

for (int j = 0; j < vertices.size(); j++) {
 currVtx = vertices.get(j);

 if (!currVtx.hasLatLong())
  continue;

 Point currentScreenPoint = getScreenPointFromGeoPoint(
   currVtx, mapview);
 if (j == 0)
  path.moveTo(currentScreenPoint.x, currentScreenPoint.y); 
          // vertex.
 else
  path.lineTo(currentScreenPoint.x, currentScreenPoint.y);

}

目前我正在使用此代码获得一个实心(填充画布的颜色)多边形。有没有办法获得未填充的多边形。有一个替代 android.graphics.Path

谢谢。

I've set of n points and I want to draw a n-sided polygon using these points.

I tried using android.graphics.path (please see below).

Path path = new Path();
Vertex currVtx;

for (int j = 0; j < vertices.size(); j++) {
 currVtx = vertices.get(j);

 if (!currVtx.hasLatLong())
  continue;

 Point currentScreenPoint = getScreenPointFromGeoPoint(
   currVtx, mapview);
 if (j == 0)
  path.moveTo(currentScreenPoint.x, currentScreenPoint.y); 
          // vertex.
 else
  path.lineTo(currentScreenPoint.x, currentScreenPoint.y);

}

Currently I'm getting a solid (filled with the color of the canvas) polygon with this code. Is there a way that I can get an unfilled polygon. There is an alternative to android.graphics.Path

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦醒灬来后我 2024-09-08 04:01:32

定义一个 Paint 对象:

Paint mPaint = new Paint();
mPaint.setStrokeWidth(2);  //2 pixel line width
mPaint.setColor(0xFF097286); //tealish with no transparency
mPaint.setStyle(Paint.Style.STROKE); //stroked, aka a line with no fill
mPaint.setAntiAlias(true);  // no jagged edges, etc.

然后使用以下方法绘制路径:

yourCanvas.drawPath(path,mPaint);

您可以查找绘图文档,但有大量选项可以控制其绘制方式。

Define a Paint object:

Paint mPaint = new Paint();
mPaint.setStrokeWidth(2);  //2 pixel line width
mPaint.setColor(0xFF097286); //tealish with no transparency
mPaint.setStyle(Paint.Style.STROKE); //stroked, aka a line with no fill
mPaint.setAntiAlias(true);  // no jagged edges, etc.

Then draw the path with:

yourCanvas.drawPath(path,mPaint);

You can look up the paint documentation but there are tons of options to control how its drawn.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文