android - 获取错误 : external allocation too large for this process

标签 android bitmap

我正在尝试执行下面的代码,将图像路径转换为位图以显示在我的 Activity 中。我收到以下错误。我尝试了很多不同的解决方案,但没有一个有效

Strange out of memory issue while loading an image to a Bitmap object

Android: Resize a large bitmap file to scaled output file

OutOfMemoryError: bitmap size exceeds VM budget :- Android

错误: E/dalvikvm-heap(19252): 12742656 字节的外部分配对于这个进程来说太大了。

for(int i = 0; i < numItems; i++) {

     File imgFile = new  File(photoPaths.get(i));

        if(imgFile.exists())
        {

             images[i] = BitmapFactory.decodeFile(imgFile.getAbsolutePath());


        }

最佳答案

您可以考虑以更即时的方式加载它们,或使用位图工厂的 inSampleSize 选项(即,您将传递一个 BitmapFactory.Options 到工厂时,inSampleSize 理想情况下设置为 2) 的幂。还要确保将 inPurgeable 设置为 true。

如果您从 MediaStoreContentProvider 中提取这些图像,您还可以使用 thumbnails .

也许您可以告诉我们更多有关您的用例的信息,以便我们提供更好的帮助。

关于android - 获取错误 : external allocation too large for this process,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10001706/

相关文章:

Android以编程方式截屏

Android:如何:通过位图设置 ImageSwitcher 的图像? setImageBitmap 不存在?

android - 回收站 View 不刷新

android - 如何以编程方式在 Android 中使用 OpenGL ES 2.0 动态绘制虚线?

android - 如何在 Android 中调整位图的大小?

c - 在 C 中为位图文件指定数组中的十六进制值

android - Android 5.0 (Lollipop) 上的海拔无法正常工作

java - Android 中使用 BluetoothChat 的多线程 : Wait for answer

javascript - Android 浏览器触摸事件停止显示正在更新公司。 Canvas /元素 - 如何解决?

java - 解密位图的像素