Android 如何使用毕加索库从 SD 卡加载图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24097576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:47:29  来源:igfitidea点击:

How to load image from SD card using Picasso library

androidpicassoimage-loading

提问by user3607798

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

我需要将 Sd 卡中的图像加载到 gridview 中。为了提高效率,我正在使用毕加索图书馆

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.

我在适配器中使用了以下代码。不幸的是,我看不到任何图像,所以请任何人帮忙。

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

注意并且任何人都可以建议任何有效的图像加载库来从 SD 卡加载图像。

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

要求我每次滚动时都不要加载图像。如果已经加载,则不要在滚动时加载图像

回答by Lena Bru

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
  • 毕加索在这方面非常出色

回答by Darshan Dorai

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

回答by cutiko

I didn't want to create a new Filebecause 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://成功了