Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 930
Shreyash Jain Avatar asked Dec 23 '15 20:12

Shreyash Jain


People also ask

How do you get pictures off of Glide?

To simply load an image to LinearLayout, we call the with() method of Glide class and pass the context, then we call the load() method, which contains the URL of the image to be downloaded and finally we call the into() method to display the downloaded image on our ImageView.

Which glide method do you use to indicate the ImageView that will contain the loaded image?

Which Glide method do you use to indicate the ImageView that will contain the loaded image? How do you specify a placeholder image to show when Glide is loading? Use the into() method with a drawable.


2 Answers

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);
like image 136
Mohit Suthar Avatar answered Oct 10 '22 16:10

Mohit Suthar


I am using this version

implementation 'com.github.bumptech.glide:glide:4.8.0'

You have to pass image uri like this given below:

 Glide.with(this)
                .load(Uri.fromFile(new File(imageStoragePath)))
                .apply(new RequestOptions().override(100, 100))
                .into(imageView);
like image 21
Prashant Sharma Avatar answered Oct 10 '22 15:10

Prashant Sharma