Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - drawline with hardware acceleration and antialiasing causes artifacts

I am working on an Android custom graph view that uses Canvas#drawLines and a paint object that has antialiasing turned on. My view has hardware acceleration turned on. Occasionally when I pinch zoom in/out, some of the lines in my graph will appear disjointed and they sort of taper off into a gradient. If I change to software layer or disable antialiasing, the issue goes away. Is this a bug with drawLines or does someone have an idea of what might be going on?

The first image exhibits the issue, the second image was moved slightly and demonstrates how the graph looks most of the time, with fully joined lines.

(image demonstrates issue) enter image description here

(image showing how graph should look - still couple minor gaps) enter image description here

like image 364
jbarr21 Avatar asked Nov 02 '22 22:11

jbarr21


2 Answers

I think this post by Romain Guy answers some of your question: http://android-developers.blogspot.com/2011/03/android-30-hardware-acceleration.html

Essentially, anti-aliasing is not supported by drawLines when hardware acceleration is turned on. Also remember that hardware acceleration won't always be 'better' for your app. If what you are drawing can be accelerated, your app will benefit from it, but for certain operations it might be worse.

I believe that explains why your lines appear disjointed when hardware accelerated. I'm not too sure it explains why it works when you turn anti-aliasing off, though. I'd imagine it would appear disjointed even with anti-aliasing off, but clearly that is not the case!

like image 145
A J Avatar answered Nov 11 '22 10:11

A J


Try forcing a refresh after the resize gestures.

Have a look at my old Accelerometer Toy app. (Yeah, it REALLY need updating...) If you don't see the problem with that app then I can probably help.

like image 27
Chris Avatar answered Nov 11 '22 10:11

Chris