简体   繁体   English

使用路径和点列表绘制多边形

[英]Drawing a polygon using Path and a List of Points

Hey I'm trying to draw a polygon with vertices as a List of Points. 嘿,我正在尝试绘制一个带有顶点的多边形作为点列表。 In my class, my List of Points is called rep. 在我的课堂上,我的积分表称为rep。 I'm not very familiar with Path but this is the code I'm using to (attempt) to draw it 我对Path不太熟悉,但这是我用来(尝试)绘制它的代码

public void draw(Canvas canvas, Paint paint){
    path.reset();
    if (type != TYPE_CIRCLE) {
        path.moveTo(rep.get(0).x, rep.get(0).y);
        for(int i = 1; i < rep.size(); i++){
            path.lineTo(rep.get(i).x, rep.get(i).y);
            path.moveTo(rep.get(i).x, rep.get(i).y);
        }
        path.close();
        canvas.drawPath(path, paint);
    }
    else{
        canvas.drawCircle(center.x, center.y, radius, paint);
    }
}

However nothing gets drawn (not on screen that is, and all points should be within the screen size. Any thoughts? Thanks in advance. 但是什么也没画(不是在屏幕上,所有点都应该在屏幕尺寸之内。有什么想法吗?在此先感谢。

Fixed it 修复

public void draw(Canvas canvas, Paint paint){
    path.reset();
    if (type != TYPE_CIRCLE) {
        path.moveTo(rep.get(0).x, rep.get(0).y);
        for(int i = 1; i < rep.size(); i++){
            path.lineTo(rep.get(i).x, rep.get(i).y);
        }
        path.lineTo(rep.get(0).x, rep.get(0).y);
        path.close();
        canvas.drawPath(path, paint);
    }
    else{
        canvas.drawCircle(center.x, center.y, radius, paint);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM