331200字节的外部分配对于此过程来说太大了

时间:2014-03-19 10:34:51

标签: android bitmap

我正在尝试在imageview上设置位图,但会给我错误,这里我已经粘贴了我的logcat

 03-19 15:49:47.675: E/AndroidRuntime(306): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
03-19 15:49:47.675: E/AndroidRuntime(306):  at android.graphics.Bitmap.nativeCreate(Native Method)
03-19 15:49:47.675: E/AndroidRuntime(306):  at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
03-19 15:49:47.675: E/AndroidRuntime(306):  at android.graphics.Bitmap.createBitmap(Bitmap.java:444)
03-19 15:49:47.675: E/AndroidRuntime(306):  at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349)
03-19 15:49:47.675: E/AndroidRuntime(306):  at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:498)
03-19 15:49:47.675: E/AndroidRuntime(306):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:473)
03-19 15:49:47.675: E/AndroidRuntime(306):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
03-19 15:49:47.675: E/AndroidRuntime(306):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
03-19 15:49:47.675: E/AndroidRuntime(306):  at android.content.res.Resources.loadDrawable(Resources.java:1709)
03-19 15:49:47.675: E/AndroidRuntime(306):  at android.content.res.Resources.getDrawable(Resources.java:581)
03-19 15:49:47.675: E/AndroidRuntime(306):  at android.view.View.setBackgroundResource(View.java:7533)
03-19 15:49:47.675: E/AndroidRuntime(306):  at nl.codestone.cookbook.incomingcallinterceptor.IncomingCallInterceptor.onReceive(IncomingCallInterceptor.java:81)
03-19 15:49:47.675: E/AndroidRuntime(306):  at android.app.ActivityThread.handleReceiver(ActivityThread.java:1794)
03-19 15:49:47.675: E/AndroidRuntime(306):  at android.app.ActivityThread.access$2400(ActivityThread.java:117)
03-19 15:49:47.675: E/AndroidRuntime(306):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:981)
03-19 15:49:47.675: E/AndroidRuntime(306):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-19 15:49:47.675: E/AndroidRuntime(306):  at android.os.Looper.loop(Looper.java:123)
03-19 15:49:47.675: E/AndroidRuntime(306):  at android.a
pp.ActivityThread.main(ActivityThread.java:3683)
03-19 15:49:47.675: E/AndroidRuntime(306):  at java.lang.reflect.Method.invokeNative(Native Method)
03-19 15:49:47.675: E/AndroidRuntime(306):  at java.lang.reflect.Method.invoke(Method.java:507)
03-19 15:49:47.675: E/AndroidRuntime(306):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-19 15:49:47.675: E/AndroidRuntime(306):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-19 15:49:47.675: E/AndroidRuntime(306):  at dalvik.system.NativeStart.main(Native Method)

我试过下面的代码。

BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 4;
        options.inScaled = false;
        Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.image1);

        overlayedButton.setBackgroundDrawable(new BitmapDrawable(bitmap));

1 个答案:

答案 0 :(得分:0)

尝试在真实设备中进行测试,而不是在模拟器中进行测试。

尝试添加

android:largeHeap

in your manifest

考虑减少起始图像的大小