android - 从移动位置的 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()
. 你能帮帮我吗?提前致谢。
解决方案
建议
你为什么不使用图像查看器库,它会为你管理所有事情,例如,你可以使用 glide 来管理所有类型的图像路径 - 本地、URL、URI 等。它还将管理图像纵横比也。
推荐阅读
- node.js - 在 aws 上部署 Angular 应用程序时,我收到 module not found express
- javascript - 给消息作者一个角色 - Discord.js
- typescript - 访问对象中的可选键,其中键是文字联合类型中的文字,没有错误“对象可能是'未定义'”
- sql - SSRS - 在单行中显示单行的值
- php - Symfony 5 无法安装 sensio/generator-bundle
- javascript - 如何在 React 中创建彩色方块板?
- javascript - 车把使用变量作为#each 对象的一部分
- flutter - 如何在颤动中保存checkboxListTile
- javascript - 如何更新js中的嵌套对象数组?
- android - 与来自 ADB Shell 的 android 通知操作进行交互