【发布时间】:2018-05-09 12:24:04
【问题描述】:
private File createImageFile() {
File picturesDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
String timeStamp = sdf.format(new Date());
File imageFile = new File(picturesDirectory, "picture" + timeStamp +".jpg");
SharedPreferences fileLocation = getSharedPreferences("filePath", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = fileLocation.edit();
editor.putString("file", imageFile.toString());
ImageView photoImg = (ImageView)findViewById(R.id.photoImg);
photoImg.setImageURI(Uri.fromFile(imageFile));
editor.commit();
return imageFile;
}
我正在尝试显示使用相机意图拍摄的图像,但是,在拍摄照片后,图像不会显示在我的 ImageView 中。图片肯定会保存,因为我可以在我的图库中查看它。
我在 stackoverflow 上环顾四周,但似乎没有一个答案对我有用,我尝试使用 BitmapFactory 但这也不起作用。任何意见将不胜感激
【问题讨论】:
-
这个
imageFile是否存在?new File()不创建文件。 -
如果
URI有效。关注This answer。 -
运行这段代码有没有抛出异常?如果是这样的话,了解我们正在处理的内容会有所帮助。发生这种情况时检查 logcat,看看是否能找到任何错误或警告,如果发现任何相关信息,请告诉我们。
-
@ADM 图像文件确实存在于路径中,因为它在我的画廊中可用,我也能够通过应用程序共享图像,只是似乎无法让它显示在图像视图中
标签: android android-intent imageview uri