如何加载与毕加索位图而不使用ImageView的? [英] How to load a Bitmap with Picasso without using an ImageView?

查看:117
本文介绍了如何加载与毕加索位图而不使用ImageView的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用的ImageView ,我可以使用下面的code下载图像回调

With ImageView, I can use the following code to download image with callback

Picasso.with(activity).load(url).into(imageView, new Callback()
{
    @Override
    public void onSuccess() 
    {
        // do something
    }

    @Override
    public void onError() { }
);

或者简单地从这个 Picasso.with(活动).load位图(URL)获得(); 。反正是有增加的回调只是下载的图片?如果可能的话,请提供样品code,干杯!

Or simply get the Bitmap from this Picasso.with(activity).load(url).get();. Is there anyway to add callback for just download the image? If possible please provide sample code, Cheers!

推荐答案

您可以创建 目标,然后办理位图里面的目标回调方法。

You can create a Target and then handle the Bitmap inside the Targets callback methods.

这是如何:

// make sure to set Target as strong reference
private Target loadtarget;

public void loadBitmap(String url) {

    if (loadtarget == null) loadtarget = new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            // do something with the Bitmap
            handleLoadedBitmap(bitmap);
        }

        @Override
        public void onBitmapFailed() {

        }
    };

    Picasso.with(this).load(url).into(loadtarget);
}

public void handleLoadedBitmap(Bitmap b) {
    // do something here
}

这篇关于如何加载与毕加索位图而不使用ImageView的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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