【问题标题】:331200-byte external allocation too large for this process331200 字节的外部分配对于此进程来说太大
【发布时间】:2014-03-19 18:44:11
【问题描述】:

我正在尝试在 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));

【问题讨论】:

    标签: android bitmap


    【解决方案1】:

    尝试在真机而不是模拟器中进行测试。

    尝试添加

    android:largeHeap
    

    in your manifest

    考虑减小起始图像的大小

    【讨论】:

    • 感谢您的回答。如果我将堆大小设置为>16,那么我将面临模拟器堆大小的问题 bcs,然后它的工作正常。虽然我的代码在设备中正常工作,但我不想冒险,我想制作稳定的代码。
    • 考虑到堆大小 16 上工作,您可以认为它是稳定的代码。但是,您可以尝试为不同的分辨率添加更多可绘制对象
    猜你喜欢
    • 1970-01-01
    • 2012-08-27
    • 2011-09-13
    • 2011-05-10
    • 1970-01-01
    • 2012-04-17
    • 1970-01-01
    • 2014-12-18
    • 1970-01-01
    相关资源
    最近更新 更多