贝塞尔曲线和帆布帆布、塞尔、曲线

2023-09-12 03:28:58 作者:Blood 血

怎样绘制贝塞尔曲线在画布上。我只有起点和终点。我想提请线从起点到终点。我怎样才能做到这一点?

How I can draw bezier curve in canvas. I have only start point and end point. I want to draw line from start point to end point. How I can do this?

推荐答案

您可以使用Path.quadTo()或Path.cubicTo()了点。实例可以在SDK实施例(FingerPaint)中找到。在你的情况,你就只需要计算中间点,然后通过你的三个点quadTo()。

You can use Path.quadTo() or Path.cubicTo() for that. Examples can be found in the SDK Examples (FingerPaint). In your case you would simply need to calculate the middle point and pass then your three points to quadTo()..

有些$ C $下您:

(X1,Y1)和(X3,Y3)是你的起始和分别结束点。

创建涂料对象一次(例如,在你的构造函数) (x1,y1) and (x3,y3) are your starting and ending points respectively.

create the paint object only once (e.g. in your constructor)

Paint paint = new Paint() {
    {
        setStyle(Paint.Style.STROKE);
        setStrokeCap(Paint.Cap.ROUND);
        setStrokeWidth(3.0f);
        setAntiAlias(true);
    }
};
final Path path = new Path();
path.moveTo(x1, y1);

final float x2 = (x3 + x1) / 2;
final float y2 = (y3 + y1) / 2;
        path.quadTo(x2, y2, x3, y3);
canvas.drawPath(path, paint);