使用Glide从SD卡加载图像 [英] Load image from SD card using Glide
问题描述
过去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
图像在给定的位置.
推荐答案
如果图像的原始路径超过了原始路径,则必须转换为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屋!