Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I draw with antialiasing on canvas?

Can I draw with anti-aliasing on canvas?

I need my circles and line have smooth edges.

like image 339
Suzan Cioc Avatar asked May 05 '12 19:05

Suzan Cioc


People also ask

What does anti aliasing do in art?

Anti-aliasing is the smoothing of jagged edges in digital images by averaging the colors of the pixels at a boundary. The letter on the left is aliased. The letter on the right has had anti-aliasing applied to make the edges appear smoother.

Can a canvas contain graphics?

<canvas>: The Graphics Canvas element. Use the HTML <canvas> element with either the canvas scripting API or the WebGL API to draw graphics and animations.

Which element is used for canvas graphics?

Element used for canvas graphics is <canvas>. The HTML canvas element is used to draw graphics, on the fly, via scripting (usually JavaScript).


2 Answers

Drawing operations want Paint. In this Paint you set Paint.setFlags(Paint.ANTI_ALIAS_FLAG)

like image 112
Alexander Kulyakhtin Avatar answered Oct 24 '22 18:10

Alexander Kulyakhtin


Check this out. It fairly uses smooth edges.. http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/FingerPaint.html

The paint properties needed to get anti-aliasing is :

     mPaint = new Paint();      mPaint.setAntiAlias(true); 

For drawing use:

     mPath = new Path();      mPath.reset();      mPath.moveTo(x, y);//can be used where to trigger the path 

onDraw method should contain:

     canvas.drawPath(mPath, mPaint); 

Declare the mPath and mPaint as global.

like image 36
Arun Chettoor Avatar answered Oct 24 '22 19:10

Arun Chettoor