【发布时间】:2010-06-01 04:20:37
【问题描述】:
我正在使用 BitmapFactory.decodeFile 将图像位图加载到我的应用程序中。但是,该函数在大图像(例如来自相机的图像)上返回 null。文件路径绝对正确,我只是不知道为什么它会返回 null。我尝试了超级采样,但似乎没有帮助。
有谁知道它为什么会这样做,或者我如何可以更轻松地将相机拍摄的图像加载到位图中?
这是我正在使用的代码:
public static Bitmap loadBitmap(String filePath){
Bitmap result = BitmapFactory.decodeFile(filePath);
if(result == null){
if(filePath.contains(".jpg") || filePath.contains(".png")){
//This is the error that occurs when I attempt to load an image from the Camera DCIM folder or a large png I imported from my computer.
Utils.Toast("Could not load file -- too big?");
} else {
Utils.Toast("Could not load file -- image file type is not supported");
}
}
return result;
}
【问题讨论】:
-
您是否将相机图像保存在 SDCard 上?路径中的所有目录都存在吗?
-
是的,图像是通过文件浏览器选择的,因此路径肯定是正确的。在同一文件夹中选择的其他(较小的)图像可以正常工作。
-
你能提供一些你正在使用的代码吗?
-
添加了我使用的代码。路径是正确的(我正在使用文件管理器来选择它),只是由于某种原因它返回 null。