如何绘制平滑/圆角路径?

2022-09-01 05:32:56

我正在创建路径,并使用 和 在每个路径中添加多行。然后绘制所有路径。但是在某些路径中的行之间有1-2个像素的空间。如何删除这些空格?我的代码是这样的:path.moveTo(x, y)path.lineTo(x, y)canvas.drawPath(path, paint)

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

答案 1

也许这会创造你想要的

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

:)


答案 2

你可能不想,然后立即这是同一点。如果这样做,则不会在两条线段上获得漂亮的角连接,这可能看起来像一个丑陋的间隙。lineTo(c, d)moveTo(c, d)

请尝试将其删除。moveTo


推荐