Java BitmapFactory打开失败:eNode(没有此类文件或目录)
我正在尝试使用Android摄像头拍摄照片,如本教程所示: 这张照片拍得很好,而且在给定的路径上也很安全。但无论如何,我得到了以下错误: 06-25 14:46:02.228 9070-9070/de.ema.flo.grapp E/BitmapFactory﹕ 无法解码流:java.io.FileNotFoundException: 文件:/storage/emulated/0/Android/data/de.ema.flo.grapp/files/Pictures/IMG_20150625_144559002.JPG: 打开失败:enoint(没有这样的文件或目录) 创建图像:Java BitmapFactory打开失败:eNode(没有此类文件或目录),java,android,image,filenotfoundexception,bitmapfactory,Java,Android,Image,Filenotfoundexception,Bitmapfactory,我正在尝试使用Android摄像头拍摄照片,如本教程所示: 这张照片拍得很好,而且在给定的路径上也很安全。但无论如何,我得到了以下错误: 06-25 14:46:02.228 9070-9070/de.ema.flo.grapp E/BitmapFactory﹕ 无法解码流:java.io.FileNotFoundException: 文件:/storage/emulated/0/Android/data/de.ema.flo.grapp/files/Pictures/IMG_20150625_
private File createImageFile() throws IOException {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmssSSS").format(new Date());
File storageDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = new File(storageDir, "IMG_" + timeStamp + ".JPG");
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
return image;
}
在意图中拍摄照片后调用以下代码
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == ACTION_TAKE_PHOTO_B && resultCode == Activity.RESULT_OK) {
if (mCurrentPhotoPath != null) {
ImageView mImageView = (ImageView) getActivity().findViewById(R.id.grillplatz_erstellen_image);
Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath);
// Associate the Bitmap to the ImageView
mImageView.setImageBitmap(bitmap);
mCurrentPhotoPath = null;
}
}
}
我也用这个试过了。但结果是一样的:FileNotFoundException
try {
InputStream is = new FileInputStream(file);
Bitmap bitmap = BitmapFactory.decodeStream(is);
} catch (FileNotFoundException e) {
e.printStacktrace();
}
这个代码有什么问题吗?我可以尝试更改什么?请检查更新的代码
private File createImageFile() throws IOException {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmssSSS").format(new Date());
File storageDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES);
if(!storageDir.isexist)
storageDir.mkdirs();
File image = new File(storageDir, "IMG_" + timeStamp + ".JPG");
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
return image;
}
让我知道它是否对您有帮助。如果您从
mCurrentPhotoPath
中删除“文件:”+
,该怎么办?谢谢@Klotor它成功地删除了“文件:”+
!难以置信的是,这让我尝试了这么长时间……甜蜜:)如果你发现自己需要创建一个文件URI,你需要去“file://”
,然后是路径(“file://”
,如果路径不是以斜杠开头)。无论如何,干得好:)@Klotor删除文件://
帮助了我。虽然我没有在路径中添加文件:
,但这并没有真正帮助我。已成功创建的文件夹和文件。起作用的是转子的回答。无论如何谢谢你!