首页 > 解决方案 > 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);

当我进行调试时,它永远不会到达onExceptiononResourceReady内的调试点。

我该如何解决这个问题?

标签: androidandroid-glide

解决方案


使用 Uri.parse(imageFile.getAbsolutePath())


推荐阅读