在画布上的Android绘图

时间:2014-02-26 12:31:24

标签: android canvas

enter image description here

我有一个画布,我正在使用点数组绘制这个图。如何用特定的颜色填充它?

protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    RectF oval = new RectF(90, 100, 200, 300);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

    paint.setColor(Color.RED);
    paint.setStrokeWidth(5f);

    //  canvas.drawRect(oval, paint);

    //canvas.drawArc(oval, 30f, 100f, true, paint);

    float [] pts = {0,200,
                    120,140,120,140,
                    180,20,180,20,
                    260,100,260,100,
                    350,20,350,20,
                    410,140,410,140,
                    530,200,530,200,
                    410,260,410,260,
                    350,380,350,380,
                    260,300,260,300,
                    180,380,180,380,
                    120,260,120,260,
                    0,200
     };

    //canvas.drawPoints(pts, paint);
    canvas.drawLines(pts, paint);

    //RectF tail = new RectF(0f, 50f, 200f,100f);   
    //canvas.drawArc(tail, 0f, 50f, true, paint);

    //canvas.drawRoundRect(oval, 20f, 20f, paint);

    invalidate();

}

基本上我想做的就是沿着数组中存在的这些点填充颜色。对此有何帮助??

1 个答案:

答案 0 :(得分:1)

您需要构建一个Path并使用canvas.drawPath。