Android canvas drawbitmap matrix

Android canvas drawbitmap matrix

0 205

I had an issue lately Android: Rotation of image around the center which was solved by the help of Unconn.

However, it turns out, that the solution – as well as it is working – does have a much worse performance, than the RotateAnimation stuff.

What I have so far: 1) FrameLayout with two ImageViews, on on top of each other 2) SensorEventHandler, which moves the lower view around according to the heading measured. This works acceptable if I use RotateAnimation

I wanted to speed it up and to smooth the animation a bit, but failed dramatically. Here is the current solution: 1) SurfaceView with separate thread, controlling the drawing of the layers 2) Without performing the code below, the thread could reach around 50 fps. 3) With the code below the frame rate goes down to 5ps and less, so it is no longer something very smooth…

Here is the code:

mRadar: Bitmap showing a “radar”, loaded from ressource earlier mHeading: The current heading taken from the sensors in degrees mRadarW,mRadarH: Initial width/height of the image, determined on creation

Matrix m = new Matrix();
m.setRotate(mHeading, mRadarW/2, mRadarH/2);
Bitmap rotated_radar = Bitmap.createBitmap(mRadar, 0, 0, mRadarW, mRadarH, m, true);
canvas.drawBitmap(rotated_radar, (mRadarW – rotated_radar.getWidth())/2, (mRadarH – rotated_radar.getHeight())/2, null);
canvas.drawBitmap(mRadar, 0, 0, null);

Is the Matrix/drawBitmap stuff known to perform not that good, in fact worse than the RotateAnimation? If there is no chance to use this: What options could you propose? Although the RotateAnimation would work for now, I would need to compose a much more complex image, before I would have to go for RotateAnimation, so I fear, I will loose again with drawBitmap and friends…



Leave a Reply