下载图像与毕加索的Andr​​oid DISCK [英] downloading images with Picasso android disck

查看:210
本文介绍了下载图像与毕加索的Andr​​oid DISCK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是毕加索库在ListView下载和显示图像,我用下面的code:

I'm using the Picasso library to download and display images in a listview, I'm using the following code:

Picasso.with(mContext).load(listItem.getMainPhoto()).into(holder.image);

其中, listItem.getMainPhoto()是一个网络链接。

但我需要下载一些图片在服务的时候,通常应用程序无法正常工作,使用户可以看到他们的时候,他是脱机的,比如我需要下载将在列表视图中使用10张更高版本。

But I need to download some of the images in a service, usually when the app is not working so the user can see them when he is off line, for example I need to download 10 images that will be used in the listview later.

所以,我有两个问题:


  1. 如何下载图像与毕加索,并将其存储在永久存储器中,所以当我使用
    Picasso.with(mContext).load(listItem.getMainPhoto())到(holder.image);

的lib将首先尝试在本地获得的形象,如果不存在它会从网上得到它?

the lib will first try to get the image locally and if is not there it will get it from the web?

2,如果解放运动在下载永久存储器中的影像,我怎么能清洁永久的记忆?

2.If the lib has download the images in permanent memory, how can i clean the permanent memory?

我想这功能都支持了毕加索的盒子,因为我有notised的LIB有时显示现金的图像。谢谢

I guess this features are supported out of the box in Picasso since i have notised that the lib sometimes is displaying the images from cash. Thanks

推荐答案

我知道这是一个老问题,但也许有人能找到这个有用。

i know this is a old question but maybe someone can find this useful.

您可以使用目标下载图像与毕加索:

you can download an image with picasso using a target:

    Picasso.with(mContext)
    .load(listItem.getMainPhoto())
    .into(target);

private Target target = new Target() {
    @Override
    public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
        new Thread(new Runnable() {
            @Override
            public void run() {               

                File file = new File(Environment.getExternalStorageDirectory().getPath() +"/imagename.jpg");
                try
                {
                    file.createNewFile();
                    FileOutputStream ostream = new FileOutputStream(file);
                    bitmap.compress(CompressFormat.JPEG, 75, ostream);
                    ostream.close();
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }

            }
        }).start();
    }
    @Override
    public void onBitmapFailed(Drawable errorDrawable) {
    }

    @Override
    public void onPrepareLoad(Drawable placeHolderDrawable) {
        if (placeHolderDrawable != null) {
        }
    }
};

要清理缓存可以将这个类添加到毕加索包:

To clean the cache you can add this class to the picasso package:

package com.squareup.picasso;

public class PicassoTools {

    public static void clearCache (Picasso p) {
        p.cache.clear();
    }
}

这篇关于下载图像与毕加索的Andr​​oid DISCK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆