簡體   English   中英

BitmapFactory 打開失敗:ENOENT(沒有那個文件或目錄)

[英]BitmapFactory open failed: ENOENT (No such file or directory)

我正在嘗試使用 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(沒有那個文件或目錄)

創建圖像:

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

在 Intent 中拍攝照片后調用以下代碼

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

讓我知道它是否對你有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM