我正在使用BitmapFactory.decodeFile将Bitmap图像加载到我的应用程序中。但是,该函数在大图像(例如来自相机的图像)上返回null。文件路径绝对正确,我只是不知道为什么它会返回null。我尝试了超取样,但似乎没有帮助。Android将相机图像加载为位图
有没有人有任何想法,为什么它会这样做,或者我怎么可以更容易地加载从相机拍摄的图像到一个位图?
下面是我使用的代码:
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;
}
您是否将相机图像保存到SD卡上?是否存在所有的路径? – 2010-06-01 07:12:59
是的,图像是通过文件浏览器选择的,所以路径一定是正确的。在同一文件夹中选择的其他(较小)图像完美地工作。 – GuyNoir 2010-06-02 15:59:37
你能提供一些你正在使用的代码吗? – Cristian 2010-06-06 04:01:51