方法drawVertices()没有吸取Android的画布什么 [英] Method drawVertices() didn't drawing anything on Android Canvas

查看:713
本文介绍了方法drawVertices()没有吸取Android的画布什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提请三角形和多边形

I would like to draw triangles, and polygons

要画一个三角形我用这个方法,我互联网上找到:

To draw a triangle I use this method that I found on internet :

this.p.setStyle(Paint.Style.STROKE);
    int triangleColors[] = {
            this.p.getColor(), this.p.getColor(), this.p.getColor(),
            this.p.getColor(), this.p.getColor(), this.p.getColor()
        };

    float verts[] = {
            ptsFloat.get(0).x, ptsFloat.get(0).y,
            ptsFloat.get(1).x, ptsFloat.get(1).y,
            ptsFloat.get(2).x, ptsFloat.get(2).y
    };
    c.drawVertices(Canvas.VertexMode.TRIANGLES, 
        verts.length, 
        verts, 
        0, 
        null,
        0,
        triangleColors,
        0,
        null, 
        0,
        0,
        this.p);

但结果是空的,我已经没有什么吸引...
然而,的drawLine,画圆工作得很好,你有什么想法,为什么这方法行不通? Futhermore,我没有在我的控制台logcat中任何痕迹,对我的帮助!

But the result is null, I've nothing drawn ... Whereas, drawLine, drawCircle works perfectly well, have you any idea why this method doesn't work ? Futhermore, I don't have any traces in my logcat console for helping me !

推荐答案

OK所以想出来为自己后,我意识到,问题是你的颜色数组。如果您使用的是相同的颜色为每一个点,那么你不需要那么数组。该的getColor()函数没有返回你所需要的INT值。如果需要不同的颜色,然后使用Color.X该颜色被分配到的三角形的部分。

OK So after trying it out for myself I realized that the issue is your color array. If you are using the same color for each point then you don't need that array. The getColor() function is not returning the int values you need. If you need different colors then use Color.X for that color to be assigned to that part of the triangle.

这篇关于方法drawVertices()没有吸取Android的画布什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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