如何绘制平滑/圆形路径? [英] How to draw smooth / rounded path?

查看:174
本文介绍了如何绘制平滑/圆形路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创造的路径,并使用 path.moveTo(X,Y) path.lineTo(X将在每个路径多行, Y)。然后 canvas.drawPath(路径,涂料)正在起草的所有路径。但也有一些路径字里行间1-2像素空间。如何删除这些空间?我的code是这样的事情:

 颜料=新的油漆();
paint.setColor(Color.RED);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setDither(假);
paint.setStrokeWidth(3);
paint.setAntiAlias​​(真正的);

的for(int i = 0; I<长度;我++){
     路径path =新路径();
     path.moveTo(A,B);
     path.lineTo(C,D);
     path.moveTo(C,D);
     path.lineTo(E,F);
     canvas.drawPath(路径,油漆);
}
 

解决方案

也许这将创造你想要什么

  paint.setColor(彩色); //设置颜色
    paint.setStrokeWidth(大小); //设置大小
    paint.setDither(真正的); //设置抖动为true
    paint.setStyle(Paint.Style.STROKE); //设置斯托克
    paint.setStrokeJoin(Paint.Join.ROUND); //设置连接圆你想
    paint.setStrokeCap​​(Paint.Cap.ROUND); //设置漆盖圆太
    paint.setPathEffect(新CornerPathEffect(10)); //设置路径的效果,当他们加入。
    paint.setAntiAlias​​(真正的); //设置抗混所以平滑
 

:)

I am creating Paths and adding multi lines in each path by using path.moveTo(x, y) and path.lineTo(x, y). Then canvas.drawPath(path, paint) is drawing all paths. But there are 1-2 pixel space between lines in some paths. 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

:)

这篇关于如何绘制平滑/圆形路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆