-1

I am making a wallpaper with different bitmaps that are moving and rotating using matrices. Right now, I have 8 bitmaps with size about 300 X 300 each as pngs. I need them to be on screen at all times. I am using this in the onCreate:

sun = BitmapFactory.decodeResource(getResources(), R.drawable.sun);
            planet_1 = BitmapFactory.decodeResource(getResources(),
                    R.drawable.planet_1);
            scene_1 = BitmapFactory.decodeResource(getResources(),
                    R.drawable.full_scaled);
            planet_2 = BitmapFactory.decodeResource(getResources(),
                    R.drawable.planet_2);
            scene_2 = BitmapFactory.decodeResource(getResources(),
                    R.drawable.scene_2);
            planet_3 = BitmapFactory.decodeResource(getResources(),
                    R.drawable.planet_3);
            scene_3 = BitmapFactory.decodeResource(getResources(),
                    R.drawable.scene_3);
            bg = BitmapFactory.decodeResource(getResources(), R.drawable.bg);

They load up in the preview well but when I try to set wallpaper it crashes with:

11-20 09:06:55.358: E/dalvikvm(6924): adjustAdaptiveCoef max=6291456, min=1572864, ut=568
11-20 09:06:55.389: E/dalvikvm(6924): adjustAdaptiveCoef max=8388608, min=2097152, ut=368
11-20 09:06:55.429: E/dalvikvm(6924): adjustAdaptiveCoef max=8388608, min=2097152, ut=256
11-20 09:06:55.899: E/dalvikvm(6924): adjustAdaptiveCoef max=4194304, min=1048576, ut=568
11-20 09:06:55.919: E/dalvikvm(6924): adjustAdaptiveCoef max=6291456, min=1572864, ut=368
11-20 09:06:56.009: E/dalvikvm(6924): adjustAdaptiveCoef max=8388608, min=2097152, ut=256
11-20 09:06:59.052: E/dalvikvm(6924): adjustAdaptiveCoef max=4194304, min=1048576, ut=568
11-20 09:06:59.122: E/dalvikvm(6924): adjustAdaptiveCoef max=6291456, min=1572864, ut=368
11-20 09:06:59.192: E/dalvikvm(6924): adjustAdaptiveCoef max=8388608, min=2097152, ut=256
11-20 09:06:59.452: E/dalvikvm(6924): adjustAdaptiveCoef max=4194304, min=1048576, ut=568
11-20 09:06:59.483: E/dalvikvm(6924): adjustAdaptiveCoef max=6291456, min=1572864, ut=368
11-20 09:06:59.483: E/dalvikvm-heap(6924): Out of memory on a 4088500-byte allocation.
11-20 09:06:59.503: E/AndroidRuntime(6924): FATAL EXCEPTION: main
11-20 09:06:59.503: E/AndroidRuntime(6924): java.lang.OutOfMemoryError
11-20 09:06:59.503: E/AndroidRuntime(6924):     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
11-20 09:06:59.503: E/AndroidRuntime(6924):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
11-20 09:06:59.503: E/AndroidRuntime(6924):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
11-20 09:06:59.503: E/AndroidRuntime(6924):     at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:472)
11-20 09:06:59.503: E/AndroidRuntime(6924):     at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:502)
11-20 09:06:59.503: E/AndroidRuntime(6924):     at com.bdcorps.PlanetMe.PlanetMain$StripedEngine.onCreate(PlanetMain.java:169)
11-20 09:06:59.503: E/AndroidRuntime(6924):     at android.service.wallpaper.WallpaperService$Engine.attach(WallpaperService.java:778)
11-20 09:06:59.503: E/AndroidRuntime(6924):     at android.service.wallpaper.WallpaperService$IWallpaperEngineWrapper.executeMessage(WallpaperService.java:1038)
11-20 09:06:59.503: E/AndroidRuntime(6924):     at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:40)
11-20 09:06:59.503: E/AndroidRuntime(6924):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-20 09:06:59.503: E/AndroidRuntime(6924):     at android.os.Looper.loop(Looper.java:137)
11-20 09:06:59.503: E/AndroidRuntime(6924):     at android.app.ActivityThread.main(ActivityThread.java:5283)
11-20 09:06:59.503: E/AndroidRuntime(6924):     at java.lang.reflect.Method.invokeNative(Native Method)
11-20 09:06:59.503: E/AndroidRuntime(6924):     at java.lang.reflect.Method.invoke(Method.java:511)
11-20 09:06:59.503: E/AndroidRuntime(6924):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
11-20 09:06:59.503: E/AndroidRuntime(6924):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
11-20 09:06:59.503: E/AndroidRuntime(6924):     at dalvik.system.NativeStart.main(Native Method)

ANy help?

2 Answers2

0

refer this Documention you will get clear about Dispalying bitmap effcienly

venu
  • 2,971
  • 6
  • 40
  • 59
0

You can try with something like this

BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inPreferredConfig = Bitmap.Config.RGB_565; // or Bitmap.Config.ARGB_4444
sun = BitmapFactory.decodeResource(getResources(), R.drawable.sun, opts);

This is the easiest approach and worth trying. Of course this will make Your graphic worse quality but depending on what they look like You may even not see the difference.

mar3kk
  • 1,886
  • 2
  • 17
  • 21