How to load image from SD card using Picasso library

被刻印的时光 ゝ 提交于 2019-11-27 03:48:54

问题


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

Picasso.with(activity).load(images.get(position).getDataPath())
            .resize(96, 96).centerCrop().into(viewHolder.image);

I used the following code in the adapter. unfortunately m unable to see any images so please can any one help.

Note And also can anyone suggest any efficient image loading library to load the images from the sd card.

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


回答1:


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



回答2:


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



回答3:


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



来源:https://stackoverflow.com/questions/24097576/how-to-load-image-from-sd-card-using-picasso-library

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