我想在画布上画一个椭圆形。基本上,我将四条贝塞尔曲线组合成一个椭圆形。
我成功画了一个椭圆形,但我不知道如何关闭它。
代码:
//Paints for bazier curve
Paint bezierPaint = new Paint();
bezierPaint.setColor(Color.RED);
bezierPaint.setStyle(Paint.Style.STROKE);
bezierPaint.setStrokeCap(Paint.Cap.ROUND);
bezierPaint.setStrokeWidth(3.0f);
bezierPaint.setAntiAlias(true);
//Oval Path
Path ovalPath = new Path();
//Draw the first curve. from top point to right point
ovalPath.moveTo(160,0);
ovalPath.cubicTo(210, 0, 260, 100, 260, 150);
//Draw the second curve. from right point to bottom point
ovalPath.moveTo(260, 150);
ovalPath.cubicTo(260, 200, 210, 300, 160, 300);
//Draw the thrid curve. from bottom point to left point
ovalPath.moveTo(160, 300);
ovalPath.cubicTo(110, 300, 60, 200, 60, 150);
//Draw the fourth curve. from left point to top point
ovalPath.moveTo(60, 150);
ovalPath.cubicTo(60, 100, 110, 0, 160, 0);
**//I expect this oval close correctly. But in actually, the fourth curve was closed.
//Please see the image in attachment.How should I close this path as my expectation?**
ovalPath.close()
canvas.drawPath(ovalPath, bezierPaint);
答案 0 :(得分:3)
只需将通话发送至path.close()
即可。此功能添加从当前绘制点到第一个绘制点的线段。我不认为跳过这个电话有任何伤害。
或者,更加注意细分的方向,以便每个细分都从最后一个结束的地方开始,更重要的是,最后一个结束于第一个开始的地方。
或者执行marnaish所说的话,而是使用drawOval()
。
答案 1 :(得分:2)