Nabin Adhikari
Nabin Adhikari

Reputation: 153

Display Uri in ImageView Android

I have a Uri of captured image from camera as "file:///storage/emulated/0/Pictures/Colony_Quantifier/IMG_20160523_204353.jpg".

While I am trying to show that image in ImageView, I am not being able to do it no matter whichever options suggested in internet.

Uri uri = Uri.parse("file:///storage/emulated/0/Pictures/Colony_Quantifier/IMG_20160523_204353.jpg");
imgCaptured.setImageURI(uri);

Upvotes: 0

Views: 4967

Answers (3)

Sharad Chauhan
Sharad Chauhan

Reputation: 4891

Try with:

ImageView.setImageURI(Uri.fromFile(new File("/sdcard/cats.jpg")));

Or:

ImageView.setImageURI(Uri.parse(new File("/sdcard/cats.jpg").toString()));

Upvotes: 3

Nongthonbam Tonthoi
Nongthonbam Tonthoi

Reputation: 12953

You may use Picasso:

Include this line in your module level build.gradle dependencies:

compile 'com.squareup.picasso:picasso:2.5.2'

then use it as:

Picasso.with(yourContext).load(uri).into(yourImageView);

Upvotes: 2

Arslan Ali
Arslan Ali

Reputation: 371

1- You create a Bitmap out of the URI

2- You create a new instance of BitmapDrawable passing in the Bitmap

3- You add the BitmapDrawable to a Window (setBackgroundDrawable), View (setBackgroundDrawable)] or ImageView (setImageDrawable)

Upvotes: 0

Related Questions