我试图将最近拍摄的图像放入imageView中。我得到正确的路径,图像在那里,但我最终在FileNotFoundException。任何人都知道接缝是什么问题?
else if (requestCode == CAMERA_RESULT) {
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath(), pictureName.toString());
Log.d("MainActivity", file.toString()); // It's the right filePath
Uri uri = Uri.fromFile(file);
Bitmap bitmap;
try {
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
mImageView.setImageBitmap(bitmap);
Log.d("MainActivity", bitmap.toString());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
这是我做的另一个尝试
else if (requestCode == CAMERA_RESULT) {
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath(), pictureName.toString());
Uri uri = Uri.fromFile(file);
InputStream inputStream;
try {
inputStream = getContentResolver().openInputStream(uri);
BitmapFactory.Options options = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
mImageView.setImageBitmap(bitmap);
Log.d("MainActivity", uri.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}