Android 位图大小超出VM预算

Android 位图大小超出VM预算,android,Android,我正在通过以下方式调整图像大小,将图像传递到xml中: scaled = Bitmap.createScaledBitmap(bp, h, w, true); imgV.setImageBitmap(scaled); 但是我得到的位图大小超过了虚拟机预算 04-30 18:36:16.552: 错误/AndroidRuntime(7164):致命 例外情况:main 04-30 18:36:16.552: 错误/AndroidRuntime(7164): java.lang.OutOf

我正在通过以下方式调整图像大小,将图像传递到xml中:

scaled = Bitmap.createScaledBitmap(bp, h, w, true);
    imgV.setImageBitmap(scaled);
但是我得到的位图大小超过了虚拟机预算

04-30 18:36:16.552: 错误/AndroidRuntime(7164):致命 例外情况:main 04-30 18:36:16.552: 错误/AndroidRuntime(7164): java.lang.OutOfMemoryError:位图 规模超过虚拟机预算04-30 18:36:16.552: 错误/AndroidRuntime(7164):在 android.graphics.BitmapFactory.NativeDecodeset(本机) 方法)04-30 18:36:16.552: 错误/AndroidRuntime(7164):在 android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460) 04-30 18:36:16.552: 错误/AndroidRuntime(7164):在 android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:525) 04-30 18:36:16.552: 错误/AndroidRuntime(7164):在 com.webrich.bachflower.TopicController.getImageBitmap(TopicController.java:103) 04-30 18:36:16.552: 错误/AndroidRuntime(7164):在 com.webrich.bachflower.TopicController.onCreate(TopicController.java:73) 04-30 18:36:16.552: 错误/AndroidRuntime(7164):在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 04-30 18:36:16.552: 错误/AndroidRuntime(7164):在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 04-30 18:36:16.552: 错误/AndroidRuntime(7164):在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 04-30 18:36:16.552: 错误/AndroidRuntime(7164):在 access$1500(ActivityThread.java:117) 04-30 18:36:16.552: 错误/AndroidRuntime(7164):在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 04-30 18:36:16.552: 错误/AndroidRuntime(7164):在 android.os.Handler.dispatchMessage(Handler.java:99) 04-30 18:36:16.552: 错误/AndroidRuntime(7164):在 Looper.loop(Looper.java:123) 04-30 18:36:16.552: 错误/AndroidRuntime(7164):在 main(ActivityThread.java:3683) 04-30 18:36:16.552: 错误/AndroidRuntime(7164):在 java.lang.reflect.Method.Invokenactive(本机) 方法)04-30 18:36:16.552: 错误/AndroidRuntime(7164):在 java.lang.reflect.Method.invoke(Method.java:507) 04-30 18:36:16.552: 错误/AndroidRuntime(7164):在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 04-30 18:36:16.552: 错误/AndroidRuntime(7164):在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 04-30 18:36:16.552: 错误/AndroidRuntime(7164):在 dalvik.system.NativeStart.main(本机) 方法)04-30 18:36:16.602: 警告/活动管理器(63):强制 整理活动 com.webrich.bachflower/.TopicController 04-30 18:36:17.132: 警告/活动管理器(63):活动 暂停超时 历史记录{407ff648 com.webrich.bachflower/.TopicController} 04-30 18:36:19.762: 调试/SntpClient(63):请求时间 失败:java.net.SocketException: 不支持的地址族 协议04-30 18:36:20.212: 信息/处理(7164):发送信号。 PID:7164信号:904-3018:36:20.302: 信息/活动管理器(63):流程 com.webrich.bachflower(pid 7164)已 死亡。04-30 18:36:20.302: 信息/窗口管理器(63):赢得死亡: 窗口{407e6b88 com.webrich.bachflower/com.webrich.bachflower.FlowerController 暂停=false}04-30 18:36:20.362: 错误/输入调度器(63):通道 '407fcdb8 com.webrich.bachflower/com.webrich.bachflower.Topics (服务器)“~消费者关闭输入 通道或发生错误。 事件=0x8 04-30 18:36:20.362: 错误/输入调度器(63):通道 '407fcdb8 com.webrich.bachflower/com.webrich.bachflower.Topics (服务器)“~通道不可恢复 破了就要处理了!04-30 18:36:20.412:INFO/WindowManager(63): 赢得死亡:窗口{407fcdb8 com.webrich.bachflower/com.webrich.bachflower.Topics 暂停=false}04-30 18:36:20.882: 警告/InputManagerService(63):获取 远程异常发送 向pid发送setActive(false)通知 7164 uid 10034


这不是这个问题的重复:

特别是,您要寻找的答案是(#评论链接):

这不是这个问题的重复:

特别是,您要寻找的答案是(#评论链接):

完全按照#注释“private Bitmap decodeFile(){…}”所说的去做。我使用了这段代码,处理的文件远远超过了内存中可以保存的文件。请完全按照#注释“private Bitmap decodeFile(){…}”中的说明执行。我使用了这段代码,处理的文件远远超出了内存中的容量。