从移动位置的URI显示ImageView? [重复]

问题描述 投票:0回答:2

这个问题在这里已有答案:

我有一个图像路径,我从相机的位置捕获

file:///storage/emulated/0/Android/data/com.xxxx.xxxxx/files/Pictures/IMG_20190312_1547177544509253258561218.jpg

我试图在ImageView中显示特定图像,我的代码是:

        File imgFile = new  File(mMediaUri.toString());
        if(imgFile.exists()){
            Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
            imageView2.setImageBitmap(myBitmap);
        } else {
            Log.d("IMAGE_PATH",mMediaUri.toString());

        }

其中mMediaUri =我上面提到的路径。但不知何故,它没有从imgFile.exists()传递循环。你能帮帮我吗?提前致谢。

android android-camera uri android-bitmap
2个回答
0
投票

Uri不能直接在文件构造函数上使用,Android反对在应用程序之间传递文件路径。

只需使用imageView2.setImageUri(mMediaUri);直。


0
投票

建议

为什么不使用图像查看器库来管理所有内容,例如,您可以使用glide来管理所有类型的图像路径 - 本地,URL,URI等。它还将管理图像宽高比太。

https://github.com/bumptech/glide

© www.soinside.com 2019 - 2024. All rights reserved.