在android中绘制斜矩形
我想在android中绘制一个矩形,但不仅仅是通过指定左、上、右和下。我所拥有的是 4 个顶点坐标。该矩形不是水平的而是倾斜的,因此类似于下面的矩形图像:
我已经一直在尝试查看是否可以使用矩阵来执行某种旋转或使用canvas.rotate(),但我仍然不清楚如何做到这一点。有人可以帮我画这样一个矩形吗?
I wanted to draw a rectangle in android, but not just by specifying the left, top, right and bottom. What I have are 4 vertex coordinates. The rectangle is not horizontal but oblique, so something like the image of the rectangle below:
I've been trying to see if I can use a matrix to perform some kind of rotation or use canvas.rotate()
, but I'm still not clear how to do it. Can somebody help me with how to draw such a rectangle?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我很想看看其他人对这个问题的解决方案,但如果没有更简单的方法,这就是我如何以困难的方式实现它:
完成这个特定的实现是为了我可以有一个填充框,它不是默认的 OpenGL ES 功能。相反,我所做的是画两个三角形。数学包括几种特殊情况,零斜率、一斜率、未定义的斜率、斜率大于 0 但小于 1 或小于零但大于负的一种情况,或者斜率大于 1 或小于阴性一例。您所要做的就是在每组点之间绘制一条线环而不是三角形,然后您将得到一个未填充的框。
I'd be interested in seeing somebody else's solution to this problem, but if there isn't an easier way, here's how I implemented it the hard way:
This particular implementation was done so that I could have a filled-in box, which is not a default OpenGL ES capability. What I did, instead, was draw two triangles. The math includes several special cases, a zero slope, a one slope, an undefined slope, a slope is greater than 0 but less than one or less than zero but greater than negative one case, or a slope is greater than one or less than negative one case. All you have to do is draw a line loop instead of a triangle between each set of points, and you'll have a non-filled box.
解决方法:
不是绘制矩形而是绘制一条线,而是设置绘画的描边宽度。
workaround :
instead of drawing rectangle draw a line but set stroke width for paint.