如何绘制Android的画布上充满三角形吗?角形、画布、Android

2023-09-12 04:04:34 作者:笑着放了自己

所以我用下面的code在我的画法绘制这个三角形在Android地图:

So I'm drawing this triangle in android maps using the code below in my draw method:

paint.setARGB(255, 153, 29, 29);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setAntiAlias(true);

Path path = new Path();
path.moveTo(point1_returned.x, point1_returned.y);
path.lineTo(point2_returned.x, point2_returned.y);
path.moveTo(point2_returned.x, point2_returned.y);
path.lineTo(point3_returned.x, point3_returned.y);
path.moveTo(point3_returned.x, point3_returned.y);
path.lineTo(point1_returned.x, point1_returned.y);
path.close();

canvas.drawPath(path, paint);

该pointX_returned是其中我从田野得到的坐标。他们基本上是经度和纬度。 其结果是一个很好的三角形,但内幕是空的,所以我可以看到地图。有没有办法以某种方式填补它?

The pointX_returned are the coordinates which I'm getting from the fields. They are basically latitudes and longitudes. The result is a nice triangle but the insider is empty and therefore I can see the map. Is there a way to fill it up somehow?

推荐答案

您可能需要做一些事情,如:

You probably need to do something like :

Paint red = new Paint();

red.setColor(android.graphics.Color.RED);
red.setStyle(Paint.Style.FILL);

和使用,而不是你的ARGB这个颜色你的路径。确保在第一个路径中的最后一个点结束,这是有道理的也。

And use this color for your path, instead of your ARGB. Make sure the last point of your path ends on the first one, it makes sense also.

告诉我,如果它的工作原理,请!

Tell me if it works please !

 
精彩推荐