[英]How to draw smooth / rounded path?
I am creating Paths and adding multi lines in each path by using path.moveTo(x, y)
and path.lineTo(x, y)
. 我正在创建路径并使用
path.moveTo(x, y)
和path.lineTo(x, y)
在每个路径中添加多行。 Then canvas.drawPath(path, paint)
is drawing all paths. 然后
canvas.drawPath(path, paint)
绘制所有路径。 But there are 1-2 pixel space between lines in some paths. 但是在某些路径中,行之间有1-2个像素空间。 How can I remove these spaces?
我怎样才能删除这些空格? My code is something like that:
我的代码是这样的:
paint = new Paint();
paint.setColor(Color.RED);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setDither(false);
paint.setStrokeWidth(3);
paint.setAntiAlias(true);
for (int i = 0; i < length; i++) {
Path path = new Path();
path.moveTo(a, b);
path.lineTo(c, d);
path.moveTo(c, d);
path.lineTo(e, f);
canvas.drawPath(path, paint);
}
Maybe this will create what you want 也许这会创造你想要的东西
paint.setColor(color); // set the color
paint.setStrokeWidth(size); // set the size
paint.setDither(true); // set the dither to true
paint.setStyle(Paint.Style.STROKE); // set to STOKE
paint.setStrokeJoin(Paint.Join.ROUND); // set the join to round you want
paint.setStrokeCap(Paint.Cap.ROUND); // set the paint cap to round too
paint.setPathEffect(new CornerPathEffect(10) ); // set the path effect when they join.
paint.setAntiAlias(true); // set anti alias so it smooths
:) :)
You probably don't want to lineTo(c, d)
and then immediately moveTo(c, d)
which is the same point. 您可能不希望
lineTo(c, d)
然后立即moveTo(c, d)
这是相同的点。 If you do this, you won't get a nice corner join on the two line segments, which may look like an ugly gap. 如果你这样做,你将不会在两个线段上得到一个漂亮的角连接,这可能看起来像一个丑陋的差距。
Try removing that moveTo
. 尝试删除该
moveTo
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.