Question about rotating a bitmap with Canvas.rotate

As we know, we can rotate a bitmap in two ways.

First way:

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

Thus, we always need to create new bitmaps for each rotation, this is not a good way for a high-performance game or application.

The second way:

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

Thus, we often avoid creating a new bitmap, but the rotation bitmap is a distortion, the quality of the bitmap is worse than the first.

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

Your comments are really appreciated!

+6
android
source share
3 answers

Make sure you provide Paint before 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); 
+2
source share

If you really need high-speed graphics applications (even 2D), you should use OpenGL on Android.

I believe that Replica uses OpenGL and VBO (where available) to render a 2D scene. But I can not find the link.

0
source share

this method should use a graphics processor to rotate the bitmap

Canvas.drawBitmap (android.graphics.Bitmap, android.graphics.Matrix, android.graphics.Paint)

0
source share

All Articles