简体   繁体   English

如何使用Picasso库从SD卡加载图像

[英]How to load image from SD card using Picasso library

i need to load images from the Sd card into gridview. 我需要将Sd卡中的图像加载到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. 注意并且任何人都可以建议任何有效的图像加载库来加载SD卡中的图像。

Requirement I dont to load the image every time when scrolling. 要求我每次滚动时都不要加载图像。 If it is already loaded dont load the image on scrolling 如果已经加载,请不要在滚动时加载图像

To load the file you need to convert it to a uri first 要加载文件,您需要先将其转换为uri

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 毕加索非常适合这一点

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 2.5.2版中,您需要将File作为参数传递给load方法,因此可以将图像加载为:

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

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). 我不想创建new File因为如果已经从现有文件获取路径,则不需要新对象(想要查看设备中已存在的图片)。

According to Picasso docs you have to do something like this: file:///android_asset/DvpvklR.png 根据毕加索的文档,你必须做这样的事情: file:///android_asset/DvpvklR.png

So I used to have: /storage/sdcard/Pictures/findyoursport/yoursport_1482358052384.jpeg 所以我曾经有过:/ /storage/sdcard/Pictures/findyoursport/yoursport_1482358052384.jpeg

Prepending: file:// did the trick 前置: file://做了伎俩

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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