【问题标题】:Display Uri in ImageView Android在 Android ImageView 中显示 Uri
【发布时间】:2016-05-23 12:31:59
【问题描述】:

我有一个从相机捕获的图像的 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);

【问题讨论】:

    标签: android imageview uri


    【解决方案1】:

    尝试:

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

    或者:

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

    【讨论】:

      【解决方案2】:

      你可以使用毕加索:

      在你的模块级 build.gradle 依赖中包含这一行:

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

      然后将其用作:

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

      【讨论】:

        【解决方案3】:

        1- 从 URI 中创建位图

        2- 你创建一个新的 BitmapDrawable 实例,传入 Bitmap

        3- 将 BitmapDrawable 添加到 Window (setBackgroundDrawable)、View (setBackgroundDrawable)] 或 ImageView (setImageDrawable)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-15
          • 1970-01-01
          • 2015-03-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多