我正在尝试执行下面的代码,将图像路径转换为位图以显示在我的 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。
如果您从 MediaStore
的 ContentProvider
中提取这些图像,您还可以使用 thumbnails .
也许您可以告诉我们更多有关您的用例的信息,以便我们提供更好的帮助。
关于android - 获取错误 : external allocation too large for this process,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10001706/