Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load a Bitmap with Picasso without using an 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() { }
);

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!

like image 780
EES Avatar asked Jun 19 '14 08:06

EES


People also ask

How do I turn an imageView into a bitmap?

Bitmap bm=((BitmapDrawable)imageView. getDrawable()). getBitmap();

How will you load an image into an imageView from an image URL using Picasso?

Image loading using Picasso is very easy, you can do it like this way Picasso. get(). load("http://i.imgur.com/DvpvklR.png").into(imageView); and in their website you can get every details. In your case you can parse every image URL and use RecyclerView to show them along with Picasso.


1 Answers

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
}
like image 137
Philipp Jahoda Avatar answered Oct 08 '22 23:10

Philipp Jahoda