How to load image from SD card using Picasso library

后端 未结 3 682
-上瘾入骨i
-上瘾入骨i 2020-12-10 11:32

i need to load images from the Sd card into gridview. For efficiency i\'m using Picasso Library

Picasso.with(activity).load(images.get(posi         


        
相关标签:
3条回答
  • 2020-12-10 12:01

    To load the file you need to convert it to a uri first

    Uri uri = Uri.fromFile(new File(images.get(position).getDataPath()));
    
    Picasso.with(activity).load(uri)
                .resize(96, 96).centerCrop().into(viewHolder.image);
    

    Requirement I dont to load the image every time when scrolling. If it is already loaded dont load the image on scrolling

    • Picasso is excellent for this
    0 讨论(0)
  • 2020-12-10 12:04

    I didn't want to create a new File because if the path was already obtained from an existing file, there is no need for a new object (want to see the already existing picture in the device).

    According to Picasso docs you have to do something like this: file:///android_asset/DvpvklR.png

    So I used to have: /storage/sdcard/Pictures/findyoursport/yoursport_1482358052384.jpeg

    Prepending: file:// did the trick

    0 讨论(0)
  • 2020-12-10 12:09

    In Picasso version 2.5.2, you need to pass a File as argument to load method, so the image can be loaded as:

    Picasso.with(context).load(new File(images.get(position).getDataPath()))
        .resize(96, 96).centerCrop().into(viewHolder.image);
    
    0 讨论(0)
提交回复
热议问题