2013-11-20 42 views
-1

我正在使用矩陣移動和旋轉的不同位圖製作壁紙。現在,我有8個大小爲300 X 300的位圖,每個都是png。我需要他們一直在屏幕上。我在OnCreate使用此:位圖加載outofmemory android

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); 

他們加載預覽很好,但是當我嘗試設置壁紙它崩潰了:

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) 

任何幫助嗎?

+0

您是否試過檢查此鏈接http://developer.android.com/training/displaying-bitmaps/index.html –

+0

在Android Manifest中添加大堆屬性 –

回答

0

你可以嘗試的東西像這樣

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); 

這是最簡單的方法和值得嘗試。當然,這會使你的圖形質量更差,但取決於它們的外觀,你甚至可能看不出它們的差異。