android - Caused by : java. lang.OutOfMemoryError: Failed to allocate a 35624972 byte allocation with 4194304 free bytes and 28MB 直到OOM

标签 android

这是我的代码:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), R.drawable.background, options);
options.inSampleSize = 2;
options.inJustDecodeBounds = false;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.background, options);
imageView.setImageBitmap(bitmap);  

正如您从代码中看到的那样,我已经尝试优化位图,并且它适用于除 Android Studio 2.0 虚拟设备(nexus 6p API23)之外的所有情况,任何人都可以给我提示吗?谢谢。

最佳答案

感谢@CommonsWare 和@petey,Loading Large Bitmaps Efficiently对我有用。

关于android - Caused by : java. lang.OutOfMemoryError: Failed to allocate a 35624972 byte allocation with 4194304 free bytes and 28MB 直到OOM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36869938/

相关文章:

c# - Xamarin.Forms - 使用默认应用打开文件

android - 如何快速添加新项目到 ListView

Android - 特定 View 上的手势检测(向上/向下滑动)

android - 支持库必须使用 compileSdkVersion 28 的确切版本规范错误

android - 如何清除 Android 4.3 上的通话记录?

android - 目标 API 级别 29 的 AndroidQ 不需要 WRITE_EXTERNAL_STORAGE 权限,它是否会破坏安全性?

android - Font Awesome 4.1.0 在 Cordova android 模拟器中不起作用

java - 使用与appengine服务器兼容的java为android客户端开发webservice(json格式)

android - 在 Android 的 ScrollView 内的 View 中进行自定义位图 blitting 时,如何确定是否会在屏幕外绘制

java - Sonar 多模块 Gradle Android 忽略projectBaseDir