I am currently drawing a Bitmap to a SurfaceView using Canvas.drawBitmap(). This seems to really reduce my framerate and I was wondering what I can do to fix this. I reference a bitmap that I have created outside the onDraw() method. I have made sure that the image is small, opaque, the pixel formats match… etc. When I don’t draw the image the framerate goes up by about 10-15 FPS. Any ideas to speed this up? I experience a noticeable lag.
I create the bitmap outside of everything…
private Bitmap bitmapPlayer = BitmapFactory.decodeResource(getResources(), R.drawable.player);
Then in my onDraw() method…
canvas.drawBitmap(bitmapPlayer, null, drawingRect, null); // drawingRect is the Rect to draw the Bitmap inside of
// ... Rest of drawing code
I can only assume you are doing something logic heavy in your draw call, If you don’t see any differences between your code and the following example,
http://www.droidnova.com/playing-with-graphics-in-android-part-iii,176.html
I would start to take a look into the following, and utilizing the graphics hardware for your drawing.
http://developer.android.com/resources/articles/glsurfaceview.html
Hope this helps