3

I am trying to use Canvas.drawLine method to draw a polygon

Here's the code that I am using

Canvas canvas = new Canvas(cache);
Paint paint = new Paint();
paint.setStrokeWidth(16);
paint.setColor(this.currentDrawing.getColor());
paint.setFlags(Paint.ANTI_ALIAS_FLAG);
systemCanvas.drawBitmap(cache, 0, 0, paint);
paint.setStrokeCap(Cap.ROOUND);
canvas.drawLine(from.getLeft(), from.getTop(), to.getLeft(), to.getTop(), paint);

And this is the output that I am getting:

enter image description here

Notice the way the lines render, they break on the round shapes and don't join smoothly. I understand why is it happening but I don't know how to make it smooth and consistent.

Any help is appreciated.

kishu27
  • 3,140
  • 2
  • 26
  • 41

3 Answers3

8

You may also want to do this

mPaint.setAntiAlias(true);

M. Usman Khan
  • 3,689
  • 1
  • 59
  • 69
  • this improves the drawing after I draw the lines using samples of the data (co-ordinates), but this alone wouldn't solve the problem. – kishu27 Oct 03 '13 at 17:03
2

Please check this answer out because it is similar to your question:

Android How to draw a smooth line following your finger

Please let me know if this helps!

Community
  • 1
  • 1
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
  • thanks.. I worked out on path already after raising the question. This is a kind of weird thing. But whenever I fall into a problem, I research well and post on SO, after which most of the time I solve it myself. Giving you a +1 and correct answer anyways :) .. Thanks – kishu27 Apr 08 '12 at 19:32
  • Thanks alot! Just curious, what kind of app are you creating? I've thought about doing something with gestures/using the draw/paint library myself :) – Jared Burrows Apr 09 '12 at 00:43
0

You need to activate hardware acceleration. If you don't activate this, you can not use method of antialias, cap, join and etc.

  • fine but this will not resolve the issue since I needed to do sampling of co-ordinates and join them instead of drawing a pixel on each sample – kishu27 Jan 23 '14 at 19:05