在ImageView Android中显示Uri

时间:2016-05-23 12:32:00

标签: android imageview uri

我有来自相机的Uri捕获图像" file:///storage/emulated/0/Pictures/Colony_Quantifier/IMG_20160523_204353.jpg"。

虽然我试图在ImageView中显示该图像,但无论在互联网上建议的任何选项,我都无法做到。

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

3 个答案:

答案 0 :(得分:3)

尝试:

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

或者:

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

答案 1 :(得分:0)

1-您从URI

创建一个位图

2-您在Bitmap中创建了一个新的BitmapDrawable实例

3-您将BitmapDrawable添加到窗口(setBackgroundDrawable),View(setBackgroundDrawable)]或ImageView(setImageDrawable)

答案 2 :(得分:0)

你可以使用毕加索:

在模块级build.gradle依赖项中包含此行:

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

然后将其用作:

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