【问题标题】:Android Drawing on Canvas画布上的 Android 绘图
【发布时间】:2014-03-29 06:52:00
【问题描述】:

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

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();

}

所以基本上我想做的就是沿着数组中存在的这些点填充颜色。有什么帮助吗??

【问题讨论】:

  • 尝试将样式应用于Paint...paint.setStyle(Paint.Style.FILL);
  • 很抱歉这样说,但它不起作用。还有其他建议吗??
  • 这些点代表什么?矩形或三角形或类似的东西?你能展示一张图片画完后的样子吗?
  • 我已经更新了我的问题,你可以看到上面的图片。谢谢
  • Pavel 之前已经[解决][1]了一个同样的问题。 [1]:stackoverflow.com/questions/3501126/…

标签: android canvas


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多