android - 位图大小超出 VM 预算

标签 android

我正在将我的图像传递到 xml,通过使用以下方法调整我的图像大小:

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

但我得到的位图大小超出了 Vm 预算。

04-30 18:36:16.552: ERROR/AndroidRuntime(7164): FATAL EXCEPTION: main 04-30 18:36:16.552: ERROR/AndroidRuntime(7164): java.lang.OutOfMemoryError: bitmap size exceeds VM budget 04-30 18:36:16.552: ERROR/AndroidRuntime(7164): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) 04-30 18:36:16.552: ERROR/AndroidRuntime(7164): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460) 04-30 18:36:16.552: ERROR/AndroidRuntime(7164): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:525) 04-30 18:36:16.552: ERROR/AndroidRuntime(7164): at com.webrich.bachflower.TopicController.getImageBitmap(TopicController.java:103) 04-30 18:36:16.552: ERROR/AndroidRuntime(7164): at com.webrich.bachflower.TopicController.onCreate(TopicController.java:73) 04-30 18:36:16.552: ERROR/AndroidRuntime(7164): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 04-30 18:36:16.552: ERROR/AndroidRuntime(7164): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 04-30 18:36:16.552: ERROR/AndroidRuntime(7164): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 04-30 18:36:16.552: ERROR/AndroidRuntime(7164): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 04-30 18:36:16.552: ERROR/AndroidRuntime(7164): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 04-30 18:36:16.552: ERROR/AndroidRuntime(7164): at android.os.Handler.dispatchMessage(Handler.java:99) 04-30 18:36:16.552: ERROR/AndroidRuntime(7164): at android.os.Looper.loop(Looper.java:123) 04-30 18:36:16.552: ERROR/AndroidRuntime(7164): at android.app.ActivityThread.main(ActivityThread.java:3683) 04-30 18:36:16.552: ERROR/AndroidRuntime(7164): at java.lang.reflect.Method.invokeNative(Native Method) 04-30 18:36:16.552: ERROR/AndroidRuntime(7164): at java.lang.reflect.Method.invoke(Method.java:507) 04-30 18:36:16.552: ERROR/AndroidRuntime(7164): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 04-30 18:36:16.552: ERROR/AndroidRuntime(7164): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 04-30 18:36:16.552: ERROR/AndroidRuntime(7164): at dalvik.system.NativeStart.main(Native Method) 04-30 18:36:16.602: WARN/ActivityManager(63): Force finishing activity com.webrich.bachflower/.TopicController 04-30 18:36:17.132: WARN/ActivityManager(63): Activity pause timeout for HistoryRecord{407ff648 com.webrich.bachflower/.TopicController} 04-30 18:36:19.762: DEBUG/SntpClient(63): request time failed: java.net.SocketException: Address family not supported by protocol 04-30 18:36:20.212: INFO/Process(7164): Sending signal. PID: 7164 SIG: 9 04-30 18:36:20.302: INFO/ActivityManager(63): Process com.webrich.bachflower (pid 7164) has died. 04-30 18:36:20.302: INFO/WindowManager(63): WIN DEATH: Window{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 (server)' ~ Consumer closed input channel or an error occurred. events=0x8 04-30 18:36:20.362: ERROR/InputDispatcher(63): channel '407fcdb8 com.webrich.bachflower/com.webrich.bachflower.Topics (server)' ~ Channel is unrecoverably broken and will be disposed! 04-30 18:36:20.412: INFO/WindowManager(63): WIN DEATH: Window{407fcdb8 com.webrich.bachflower/com.webrich.bachflower.Topics paused=false} 04-30 18:36:20.882: WARN/InputManagerService(63): Got RemoteException sending setActive(false) notification to pid 7164 uid 10034

最佳答案

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

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

关于android - 位图大小超出 VM 预算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5840753/

相关文章:

java - 无法填充 ListView 未调用 getView

android - 获取所有屏幕坐标

android - 如何引导用户单击 View ?

java - 将数据从编辑文本传递到 Java 对象,

android - 在Android中使用kotlin下载文件并将其保存到下载文件夹

android - 无法使用 Theme.AppCompat 设置十六进制颜色和查看操作栏上的图标

android - 如何通过触摸按钮在android中添加网站链接

java - 浏览屏幕 android 开发

android - 如何在 Android 中设置 Alert Dialog 的高度和宽度?

java - 我从 MQTT 接收消息的代码不起作用?