Reputation: 1331
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
Upvotes: 1
Views: 2553
Reputation: 512
How large is the Bitmap you are using for the background. If it is over-sized and only one size and not created for hdpi, mdpi, etc, then you may be referencing a image unnecessarily large. If this is the case, I would use the BitmapFactory class to create a scaled down version of the image that matches the width and height of the Canvas.
P.S. png images are recommended as they are most efficient.
Upvotes: 0
Reputation: 2617
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
Upvotes: 1