java - 如何绘制平滑/圆润的路径?

标签 java android path paint

我正在创建路径并使用 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.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

:)

关于java - 如何绘制平滑/圆润的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7608362/

相关文章:

Java:即使使用 SwingUtilities.invokeLater,线程也不会修改 GUI

internet-explorer - 强制 Internet Explorer 使用特定的 Java 运行时环境安装?

android - kitkat 中的 CardView 和 RecyclerView

android - 在 Android 中为 ADB 部署的应用程序授予权限

java - 我的 Android 应用程序崩溃了,不理解 Eclipse 中的 Logcat

windows - 如何使用命令行更改Grails版本?

Python - 以编程方式获取文件路径?

java - 使用 Java Kubernetes 客户端 Api 部署 Pod

java - Servlet 对 Android 设备的响应

variables - 用于导出变量的 Puppet list