需求实现
-
通过相机或者图库,获得图片文件的路径,是
String
类型的,比如叫imagePath
-
通过资源表示,获得
ImageView
对象
ImageView imageView = findViewById(R.id.upload_identify_navigate);
- 通过将路径-》文件-》Uri的转换,设置图片
imageView.setImageURI(Uri.fromFile(new File(imagePath)));
问题
如果图片内容改了,但是imagePath
不变,那么图片内容不会改变。
修改
转化为Bitmap
,就能反映图片的变化
try {
Bitmap bmp = MediaStore.Images.Media.getBitmap(getContentResolver(), Uri.fromFile(new File(imagePath)));
imageView.setImageBitmap(bmp);
} catch (IOException e) {
e.printStackTrace();
}
网友评论