android - animation by drawing bitmap is not smoot

2019-08-28 20:58发布

问题:


I am trying to animate several shapes(paths) by drawing them on the surface holders canvas. At first I was drawing them as paths and everything was fine, the movement was smooth. As I increased the number of objects(shapes) the performance decreased and I made some tests to see if instead of drawing shapes drawing bitmaps is faster. And.. drawing bitmaps seems to be considerable faster (less computation maybe) BUT the movement is not smooth. It looks like the bitmaps always move from pixel to pixel instead of using anti alias to, I dont know, draw states as half pixel. The signature of the method looks like :

canvas.drawBitmap(cloudBitmap, float left, float top, Paint p);


which suggests that I should be able to draw a bitmap at 0.5f pixels.

Any idea why ?

回答1:

I think it might be due to the bitmap being drawn without filtering it for smoothness. Have you set the paint to smooth the bitmap? If not, that might be your solution.

Paint paint = new Paint();
paint.setFilterBitmap(true);