Android: Is there any way of speeding up canvas.drawBitmap?

Simple question, not sure sure there’s a simple answer though!!

Is there anything at all that I can do to speed up my surfaceview drawing?

  • OutOfMemoryError when compiling my android app with gradle
  • Android : Accessing container activity object from fragment using putExtra?
  • combining two png files in android
  • Camera picture to Bitmap results in messed up image
  • Error : ConnectionResult{statusCode=INTERNAL_ERROR, resolution=null}
  • Listactivity error with jelly bean running device ( SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length)
  • I’m using something like this:

    c.drawBitmap(scaledSprite, X, Y, redPaint);
    

    The method that I’m using has to draw about 25 of these sprites on the screen, so I’m using a for loop, meaning it has to display 25 during a frame.

    Now, this works absolutely fine on the 3 phones that I’ve tested on, but on a tablet, it just slows down. I’ve commented out all the other drawing methods and left just this one and this is definitely what is slowing the game down.

    Are there any clever tips anyone can give me to speed this up?

    I know open GL is a possibility but the bulk of the game is now written so I don’t really want to make any drastic changes now if I can help it.

    Related posts:

    How to disable action bar permanently
    Live stream RTMP/RTSP player without using webview (WOWZA server) on Android
    Supporting both landscape orientations in Honeycomb
    What is the purpose of a delegation pattern?
    Android : App support for multiple tablet screen resolutions
    Cordova does not actually install app on android device
  • What exactly does fitsSystemWindows do?
  • Fused Location Provider setsmallestDisplacement doesn't work in Android
  • Saving CookieStore in http client service
  • Android: How to sum all the columns in a SQLite database and return 1 single variable
  • when is smart to use bindService and when startService
  • Secure Asset/Media Folder through Auth Controller ? Laravel 5.2
  • One Solution collect form web for “Android: Is there any way of speeding up canvas.drawBitmap?”

    If you set your SurfaceView to lower quality graphics

    getHolder().setFormat(0x00000004); //RGB_565
    

    and load all bitmaps in the same config

    Options options = new BitmapFactory.Options();
    options.inScaled = false; 
    options.inPreferredConfig = Bitmap.Config.RGB_565;
    

    This would make it faster, plus you would need to make variable movement speed of sprites depending on the frame delay.

    However, even with these settings an arcade game with many sprites will not work well on a tablet, hence, I am afraid, if you want to make a proper game that sells, you must create an OpenGl framework or use ready made ones.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.