Android:FrameAnimation和Bitmap大小超过

时间:2013-02-12 13:43:59

标签: android animation memory bitmap

阅读stackoverflow站点中的几篇帖子后 我尝试使用Frame动画

来构建动画
private void startAnimation(){
    fireAnimation = new AnimationDrawable();
    fireAnimation.addFrame(getResources().getDrawable(R.drawable.fire1), 100);
    fireAnimation.addFrame(getResources().getDrawable(R.drawable.fire2), 100);
    fireAnimation.addFrame(getResources().getDrawable(R.drawable.fire3), 100);
    fireAnimation.addFrame(getResources().getDrawable(R.drawable.fire4), 100);
    ...
   fireAnimation.addFrame(getResources().getDrawable(R.drawable.fire16), 100);

}

然后在onCreate()中我做startActivity();

But I have an error
02-12 13:31:31.909: E/dalvikvm-heap(4902): 1535664-byte external allocation too large for this process.
02-12 13:31:31.909: E/GraphicsJNI(4902): VM won't let us allocate 1535664 bytes
02-12 13:31:31.939: W/dalvikvm(4902): threadid=1: thread exiting with uncaught exception (group=0x40018560)
02-12 13:31:31.959: E/AndroidRuntime(4902): FATAL EXCEPTION: main
02-12 13:31:31.959: E/AndroidRuntime(4902): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
02-12 13:31:31.959: E/AndroidRuntime(4902):     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at android.content.res.Resources.loadDrawable(Resources.java:1709)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at android.content.res.Resources.getDrawable(Resources.java:581)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at com.example.kersplatt.GameActivity.startAnimation(GameActivity.java:244)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at com.example.kersplatt.GameActivity.access$0(GameActivity.java:237)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at com.example.kersplatt.GameActivity$1.onTouch(GameActivity.java:80)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at android.view.View.dispatchTouchEvent(View.java:3881)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1738)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1127)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1722)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2196)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1880)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at android.os.Looper.loop(Looper.java:130)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at android.app.ActivityThread.main(ActivityThread.java:3683)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at java.lang.reflect.Method.invokeNative(Native Method)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at java.lang.reflect.Method.invoke(Method.java:507)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
02-12 13:31:31.959: E/AndroidRuntime(4902):     at dalvik.system.NativeStart.main(Native Method)

我有16张图片,当我只放4张图片时。 我能做些什么来减轻图像的重量?我应该减小尺寸(600 * 650)m,哪些足以保证质量好?

1 个答案:

答案 0 :(得分:0)

您可以缩小图像尺寸 要么 您可以尝试增加VM堆。

尝试在adb shell中设置以下内容。

setprop dalvik.vm.heapsize“12m”