【发布时间】:2018-06-05 18:04:58
【问题描述】:
我正在使用文件选择器将图像作为文件获取,然后我想使用 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.fromFile(imageFile)那样加载,只需使用load(imageFile.getPath())。 -
我试过了,但结果是一样的。它不会使用 imageFile.getPath 加载图像。
-
您确定
getApplicationContext()返回一个有效的context吗?
标签: android android-glide