Set Imageview to show image in sdcard?

2019-01-13 20:40发布

I have a image stored in SD card of my phone. I want to show it in a image view. I know the location of the file. On the oncreate of the activity is there a simple way to say something like

ImageView img = (ImageView) findViewById(R.id.imageView1);    
String path = Environment.getExternalStorageDirectory().toString() "Images/image.jpg";     
img.setsrc = path ;

Please let me know if there is any way to do this. Thank you.

2条回答
等我变得足够好
2楼-- · 2019-01-13 21:06

I have this snippet that may help:

File imageFile = new  File("/sdcard/example/image.jpg"); 
if(imageFile.exists()){
    ImageView imageView= (ImageView) findViewById(R.id.imageviewTest);
    imageView.setImageBitmap(BitmapFactory.decodeFile(imageFile.getAbsolutePath()));
}

:)

查看更多
萌系小妹纸
3楼-- · 2019-01-13 21:24
Bitmap bmp = BitmapFactory.decodeFile(pathName);
ImageView img;
img.setImageBitmap(bmp);

Hope this helps.

查看更多
登录 后发表回答