Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
388 views
in Technique[技术] by (71.8m points)

android - Load image from SD card using Glide

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...