简体   繁体   中英

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.

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

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

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


File file = new File(Environment.getExternalStorageDirectory()+File.separator+"xxx/xxx/"+imgName.jpg);
                        Uri imageUri = Uri.fromFile(file);
                        Glide.with(this).load(imageUri).into(tvBestSellingProductImage3);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM