位图大小超过VM预算

时间:2011-04-30 09:08:16

标签: android

我将图像传递给xml,方法是使用以下方法调整图像大小:

scaled = Bitmap.createScaledBitmap(bp, h, w, true);
    imgV.setImageBitmap(scaled);

但我的位图大小超过了Vm预算。

  

04-30 18:36:16.552:   错误/ AndroidRuntime(7164):致命   例外:主04-30 18:36:16.552:   ERROR / AndroidRuntime(7164):   java.lang.OutOfMemoryError:位图   大小超过VM预算04-30   18:36:16.552:   错误/ AndroidRuntime(7164):at   android.graphics.BitmapFactory.nativeDecodeAsset(母语   方法)04-30 18:36:16.552:   错误/ AndroidRuntime(7164):at   android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)   04-30 18:36:16.552:   错误/ AndroidRuntime(7164):at   android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:525)   04-30 18:36:16.552:   错误/ AndroidRuntime(7164):at   com.webrich.bachflower.TopicController.getImageBitmap(TopicController.java:103)   04-30 18:36:16.552:   错误/ AndroidRuntime(7164):at   com.webrich.bachflower.TopicController.onCreate(TopicController.java:73)   04-30 18:36:16.552:   错误/ AndroidRuntime(7164):at   android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)   04-30 18:36:16.552:   错误/ AndroidRuntime(7164):at   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)   04-30 18:36:16.552:   错误/ AndroidRuntime(7164):at   android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)   04-30 18:36:16.552:   错误/ AndroidRuntime(7164):at   android.app.ActivityThread.access $ 1500(ActivityThread.java:117)   04-30 18:36:16.552:   错误/ AndroidRuntime(7164):at   android.app.ActivityThread $ H.handleMessage(ActivityThread.java:931)   04-30 18:36:16.552:   错误/ AndroidRuntime(7164):at   android.os.Handler.dispatchMessage(Handler.java:99)   04-30 18:36:16.552:   错误/ AndroidRuntime(7164):at   android.os.Looper.loop(Looper.java:123)   04-30 18:36:16.552:   错误/ AndroidRuntime(7164):at   android.app.ActivityThread.main(ActivityThread.java:3683)   04-30 18:36:16.552:   错误/ AndroidRuntime(7164):at   java.lang.reflect.Method.invokeNative(母语   方法)04-30 18:36:16.552:   错误/ AndroidRuntime(7164):at   java.lang.reflect.Method.invoke(Method.java:507)   04-30 18:36:16.552:   错误/ AndroidRuntime(7164):at   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839)   04-30 18:36:16.552:   错误/ AndroidRuntime(7164):at   com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)   04-30 18:36:16.552:   错误/ AndroidRuntime(7164):at   dalvik.system.NativeStart.main(母语   方法)04-30 18:36:16.602:   WARN / ActivityManager(63):强制   整理活动   com.webrich.bachflower / .TopicController   04-30 18:36:17.132:   WARN / ActivityManager(63):活动   暂停超时   HistoryRecord {407ff648   com.webrich.bachflower / .TopicController}   04-30 18:36:19.762:   DEBUG / SntpClient(63):请求时间   失败:java.net.SocketException:   地址系列不受支持   议定书04-30 18:36:20.212:   INFO / Process(7164):发送信号。   PID:7164 SIG:9 04-30 18:36:20.302:   INFO / ActivityManager(63):进程   com.webrich.bachflower(pid 7164)有   死了。 04-30 18:36:20.302:   INFO / WindowManager(63):胜利死亡:   窗口{407e6b88   com.webrich.bachflower / com.webrich.bachflower.FlowerController   paused = false} 04-30 18:36:20.362:   ERROR / InputDispatcher(63):channel   “407fcdb8   com.webrich.bachflower / com.webrich.bachflower.Topics   (服务器)'〜消费者关闭输入   通道或发生错误。   events = 0x8 04-30 18:36:20.362:   ERROR / InputDispatcher(63):channel   “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   暂停=假} 04-30 18:36:20.882:   WARN / InputManagerService(63):得到了   RemoteException发送   setActive(false)通知pid   7164 uid 10034

1 个答案:

答案 0 :(得分:1)

这不是这个问题的重复: Strange out of memory issue while loading an image to a Bitmap object

特别是,您正在寻找的答案是(#comment link): Strange out of memory issue while loading an image to a Bitmap object