Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Question about rotate bitmap with Canvas.rotate

Tags:

android

As we know, we can rotate a bitmap through 2 ways.

The 1st way is:

Matrix mt = new Matrix(); 
mt.postRotate(degree); 
Bitmap bitmap = CreateBitmap(src, 0, 0, w, h, mt, true); 
canvs.drawBitmap(bitmap, 0, 0, paint); 

In this way, we always need create new bitmap for every rotation, it is not good way for high performance game or app.

The 2nd way is:

canvas.save(); 
canvas.rotate(degree); 
canvas.drawBitmap(bitmap, 0, 0, paint); 
canvas.restore(); 

In this way, we avoid creating new bitmap frequently, but the rotation bitmap is distortion, the bitmap quality is worse than first way.

So, Is there 3rd way to rotate bitmap with high performance and good quality?

Your any comments are really appreciated!

like image 783
user457210 Avatar asked Sep 24 '10 12:09

user457210


1 Answers

Make sure that you providing Paint to canvas.drawBitmap(bitmap, 0, 0, paint).

And don't forget to use anti-alias and bitmap filtering:

paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
like image 94
Dmitry Zaytsev Avatar answered Oct 10 '22 08:10

Dmitry Zaytsev