1

I am developing a live wallpaper that reproduces an animation (like a short video) on background.

Does anyone know how to efficiently load various full screen size bitmaps and draw them on canvas? I have tried 2 approaches and both are not very good.


Approach #1: Load all bitmaps on wallpaper startup.

Problem: Memory excess limit (about 35MB) cant load more than 10 bitmaps. So animations lack of different images.


Approach #2: Load only 2 bitmaps. On run time, paint bitmap, delete old bitmap, load new bitmap, repeat.

Problem: Consumes a lot of the system, (not memory, but slows down os in general), however it works because it doesn't exceed memory limit. But still, slows down the entire system.

example:

  Drawer.drawAll(res,c,p);
  res.removeOldBitmaps();
  res.loadNewBitmaps(wpservice,display);

A different approach i thought about is load resource on a separete thread, what do you guys think of that? do you have any other solutions?

Cheers!

chelo_c
  • 1,739
  • 3
  • 21
  • 34
  • You could do with one Bitmap only too. This could be achieved if you preload images into memory as byte arrays (png compressed for example) and decode only one at a time. Should this speed up the decoding process a bit compared to loading from resources at least. But if you're into video alike outcome why not make a video and use MediaPlayer? – harism Jan 10 '13 at 18:01
  • Hey, that's a good idea, i will try it out and see if there are any improvements. No, i cant use media player on a live wallpaper, i dont know if it is possible, and even if it is, i plan to do some animations. Thanks for the response. – chelo_c Jan 10 '13 at 18:05
  • Here i found a similar post with an intersteing question, however i havent tried it yet:http://stackoverflow.com/questions/10133306/android-live-wallpaper-animation [link](http://stackoverflow.com/questions/10133306/android-live-wallpaper-animation) – chelo_c Jan 10 '13 at 18:07
  • Just in case you get interested in trying out the MediaPlayer approach, it's doable with OpenGL ES 2.0 and SurfaceTexture (API 11+ only though) at least. Without OpenGL I have no idea is it possible to have MediaPlayer render its contents on wallpaper surface. – harism Jan 10 '13 at 18:10
  • Ohh thanks, i will take a look. However i wanted the wallpaper to work from API 9. – chelo_c Jan 10 '13 at 18:36

1 Answers1

0

Solved, the solution I found was the following:

Load images on runtime, 1 by 1.

And use this options:

/**Effective image decoder by chelin**/
public static Bitmap decodeResource(WallpaperService wpservice,int id){

    int scale=1;
    Resources res = wpservice.getResources();
    BitmapFactory.Options o2 = new BitmapFactory.Options();
    o2.inPreferredConfig = Bitmap.Config.ARGB_8888;
    o2.inSampleSize=scale;
    o2.inPurgeable = true;
    o2.inInputShareable = true;
    return BitmapFactory.decodeResource(res, id, o2);
}

Hope it works as it worked for me. Cheers!

chelo_c
  • 1,739
  • 3
  • 21
  • 34
  • 1
    If you don't care about transparency you can save memory by using Bitmap.Config.RGB_565 – James Sep 18 '14 at 14:38