如何在不使用 ImageView 的情况下使用 Picasso 加载位图? [英] How to load a Bitmap with Picasso without using an ImageView?

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

问题描述

使用ImageView,我可以使用下面的代码通过回调下载图片

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(activity).load(url).get(); 获取位图.无论如何要添加回调以仅下载图像?如果可能,请提供示例代码,干杯!

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!

推荐答案

你可以创建一个 Target 然后修改里面的Bitmap目标回调方法 onBitmapLoaded(...).方法如下:

You can create a Target and then modify the Bitmap inside the Targets callback method onBitmapLoaded(...). Here is how:

// 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 的情况下使用 Picasso 加载位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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