BitmapFactory打开失败:ENOENT(没有这样的文件或目录)

时间:2015-06-25 13:09:14

标签: java android image filenotfoundexception bitmapfactory

我正在尝试使用Android相机意图拍摄照片,如本教程所示:http://developer.android.com/training/camera/photobasics.html#TaskScalePhoto

照片完美拍摄,并在指定的路径上也安然无恙。但无论如何我得到了以下错误:

  

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:   打开失败:ENOENT(没有这样的文件或目录)

创建图片:

jb

在意图中拍摄照片后调用以下代码

jc

我也试过这个。但结果是一样的:FileNotFoundException ...

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;
}

此代码有任何问题吗?我可以尝试改变什么?

1 个答案:

答案 0 :(得分:1)

请检查更新的代码。

    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;
    }

让我知道它是否会对你有所帮助。

相关问题