Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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). 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); } 
like image 762
Onuray Sahin Avatar asked Sep 30 '11 09:09

Onuray Sahin


People also ask

What tool draws smooth edge paths?

The Pen tool allows you to draw smooth-edged paths with anchor points and handles. Select the Pen tool (P) .

Which tool is best for creating long smooth paths and curves?

Instead of drawing and modifying paths using Bezier curves, use the Curvature Pen tool in Adobe Photoshop to create paths intuitively, and then simply push and pull segments to modify them.


2 Answers

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 

:)

like image 66
Terence Lui Avatar answered Oct 01 '22 00:10

Terence Lui


You probably don't want to lineTo(c, d) and then immediately moveTo(c, d) which is the same point. 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.

like image 35
Graham Borland Avatar answered Sep 30 '22 23:09

Graham Borland