【问题标题】:How to draw smooth / rounded path?如何绘制平滑/圆润的路径?
【发布时间】:2011-11-28 07:57:34
【问题描述】:

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

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

【问题讨论】:

  • 你需要把你的代码放上来。
  • 你试过在你的 Paint 对象上设置抗锯齿吗?

标签: java android 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

    【讨论】:

      猜你喜欢
      • 2023-03-21
      • 2011-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-12
      • 2015-11-18
      • 1970-01-01
      相关资源
      最近更新 更多