首页 > 解决方案 > 从移动位置的 URI 显示 ImageView?

问题描述

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

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(). 你能帮帮我吗?提前致谢。

标签: androidandroid-camerauriandroid-bitmap

解决方案


建议

你为什么不使用图像查看器库,它会为你管理所有事情,例如,你可以使用 glide 来管理所有类型的图像路径 - 本地、URL、URI 等。它还将管理图像纵横比也。

https://github.com/bumptech/glide


推荐阅读