如何绘制Android的画布上充满三角形吗? [英] How to draw a filled triangle in android canvas?

查看:526
本文介绍了如何绘制Android的画布上充满三角形吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我用下面的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 !

这篇关于如何绘制Android的画布上充满三角形吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆