android根据图片路径显示图片

时间:2023-03-09 20:58:38
android根据图片路径显示图片

首先根据图片路径先创建一个文件path为图片路径;然后判断文件是否存在,如果存在,将图片显示出来。

File file = new File(path);

ImageView img = (ImageView) findViewById(R.id.img);

if(file.exists()){

Bitmap bm = BitmapFactory.decodeFile(path);

img.setImageBitmap(bm);

}