Load image from SD card using Glide

匿名 (未验证) 提交于 2019-12-03 01:23:02

问题:

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.

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);

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

The image is present in the given location.

回答1:

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);

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

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


回答2:

You have to pass image uri like this given below:

 Glide.with(this)                 .load(Uri.parse("file:///sdcard/img.png"))                 .override(612, 816)                 .into(imageView);


回答3:

Just use below line:-

Glide.with(context).load(uri).transform(new Transform()).into(view)

And for getting uri use below code:-

 Uri.fromFile(new File(Yourpath));


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!