有谁知道android里的Path类中的quadTo()方法是怎么实现贝塞尔曲线...
发布网友
发布时间:2022-05-12 15:21
我来回答
共1个回答
热心网友
时间:2022-05-12 18:19
/**
* 画曲线(核心代码)
*
* @param startp
* 开始点
* @param endp
* 结束点
* @param canvas
* 画布
* @param paint
* 画笔
*/
private void drawCurve(Point[] points, Canvas canvas, Paint paint)
{
Point startp = new Point();
Point endp = new Point();
for (int i = 0; i < points.length - 1; i++)
{
startp = points[i];
endp = points[i + 1];
int wt = (startp.x + endp.x) / 2;
Point p3 = new Point();
Point p4 = new Point();
p3.y = startp.y;
p3.x = wt;
p4.y = endp.y;
p4.x = wt;
// 确定曲线的路径
path = new Path();
path.moveTo(startp.x, startp.y);
path.cubicTo(p3.x, p3.y, p4.x, p4.y, endp.x, endp.y);
canvas.drawPath(path, paint);
}
}