使用 Glide 从 SD 卡加载图像 [英] Load image from SD card using Glide

查看:59
本文介绍了使用 Glide 从 SD 卡加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的 5 个小时里,我一直在努力寻找答案.我正在将图像从 google plus 存储到本地文件夹并使用 Glide 库将图像加载到 imageview 中.

I've been trying and searching for an answer for the past 5 hours. I'm storing image from google plus to local folder and using Glide library to load the image into imageview.

文件uri是file:///storage/emulated/0/MyApp/ProfilePics/profile_user1.jpg

the file uri is file:///storage/emulated/0/MyApp/ProfilePics/profile_user1.jpg

我正在使用以下代码通过滑行加载图像:

I'm using below code for image loading through glide:

Glide.with(ProfileActivity.this).load(Uri.fromFile(new File(sharedPrefMan.getImageUrl()))).placeholder(R.drawable.placeholder_profile).into(imgProfilePic);

其中 sharedPrefMan.getImageUrl() 返回/storage/emulated/0/MyApp/ProfilePics/profile_user1.jpg

where sharedPrefMan.getImageUrl() returns /storage/emulated/0/MyApp/ProfilePics/profile_user1.jpg

图像出现在给定的位置.

The image is present in the given location.

推荐答案

如果您有图像的原始路径,则必须转换为 URI 并像这样显示图像

If you have original path of image than you have to converted to URI and showing image like this

    String fileName = "1.jpg";
    String completePath = Environment.getExternalStorageDirectory() + "/" + fileName;

    File file = new File(completePath);
    Uri imageUri = Uri.fromFile(file);

    Glide.with(this)
            .load(imageUri)
                    .into(imgView);

好像你有 URI 而不是你必须放的 URI

Seems like you have URI than you have to put than URI only

   Glide.with(this)
            .load(Uri)
                    .into(imgView);

这篇关于使用 Glide 从 SD 卡加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆