android - Glide 不从文件加载图像
问题描述
我正在使用文件选择器将图像作为文件获取,然后我想使用 Glide 将其加载到 ImageView 中。
我正在尝试使用此代码,但无法将图像加载到图像视图中。
Glide.with(getApplicationContext())
.load(Uri.fromFile(imageFile))
.error(R.drawable.ic_person_gray)
.listener(new RequestListener<Uri, GlideDrawable>() {
@Override public boolean onException(
Exception e, Uri model, Target<GlideDrawable> target, boolean isFirstResource
) {
Timber.d(e.getMessage());
return false;
}
@Override public boolean onResourceReady(
GlideDrawable resource,
Uri model,
Target<GlideDrawable> target,
boolean isFromMemoryCache,
boolean isFirstResource
) {
editProfilePresenter.uploadProfilePicture(imageFile);
return false;
}
})
.into(ivAvatar);
当我进行调试时,它永远不会到达onException或onResourceReady内的调试点。
我该如何解决这个问题?
解决方案
使用 Uri.parse(imageFile.getAbsolutePath())
推荐阅读
- docker - 面临将我的 traefik 设置升级到 docker swarm 的问题
- javascript - 为什么 PayPal 无法识别我的 Items Array?
- batch-file - 批处理循环变量操作
- c# - 上传后 Amazon S3 不释放文件
- ios - 在语句中调整 iPhoneX / iPad / iPhone6 的 UIView 位置
- java - 从长度为 N 的 Java.util.LinkedList 前面的 N 个删除操作的时间复杂度
- applescript - AppleScript 在 10.15.4 更新后无法正常工作
- python - 为 python 聊天机器人提供用户界面的最佳方式是什么?
- python - 创建一个滚动总和列,一旦达到阈值就会重置
- java - Android BottomNavigationBar 使用 ConstraintLayout 和 ScrollView