gpt4 book ai didi

Android 在 Canvas 上绘图

转载 作者:太空宇宙 更新时间:2023-11-03 10:46:49 27 4
gpt4 key购买 nike

enter image description here

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

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

}

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

最佳答案

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

关于Android 在 Canvas 上绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22041473/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com