Android: canvas.drawBitmap performance issue

Recently, I had an Android problem : rotating the image around the center , which was resolved using Unconn.

However, it turns out that the solution โ€” and how it works โ€” has much worse performance than RotateAnimation.

What I still have: 1) FrameLayout with two ImageViews, on top of each other 2) SensorEventHandler, which moves the bottom view around according to the measured title. It works if I use RotateAnimation

I wanted to speed it up and smooth the animation a bit, but it failed dramatically. Here is the current solution: 1) SurfaceView with a separate thread controlling the drawing of layers 2) Without executing the code below, the stream can reach 50 frames per second. 3) When using the code below, the frame rate decreases to 5ps or less, so this is no longer something very smooth ...

Here is the code:

mRadar: raster image with the image of a โ€œradarโ€ downloaded from ressource previously mHeading: current title taken from sensors in degrees mRadarW, mRadarH: The initial width / height of the image determined when creating

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 it known that Matrix / drawBitmap does not work as well, is it actually worse than RotateAnimation? If itโ€™s not possible to use this: what options could you offer? Although RotateAnimation will now work, I will need to compose a much more complex image before I have to go to RotateAnimation, so I am afraid that I will lose drawBitmap and friends again ...

Oh, I missed CALayers :)

+1
source share
1 answer

It's very fast:

 canvas.save(); //save the position of the canvas canvas.rotate(angle, X + (ballW / 2), Y + (ballH / 2)); //rotate the canvas canvas.drawBitmap(ball, X, Y, null); //draw the ball on the rotated canvas canvas.restore(); //"rotate" the canvas back so that it looks like the ball has rotated 

I use a nice 32-bit png image, so I donโ€™t need any filter or anti-alias Paint ... what image do you use for this sprite?

+2
source

Source: https://habr.com/ru/post/1342140/


All Articles