sof question
sof question

Reputation: 93

How to store Image that is download by Picasso in android?

I am building android application and using Picasso lib to download the image from url.

Now I wanna to download and store in app so I can use it any time any where I need it.

I am using below code to download the image

Picasso.with(getActivity())
            .load(profilePic)
            .transform(new CircleTransform())
            .into(userimg);

Upvotes: 1

Views: 923

Answers (1)

shkschneider
shkschneider

Reputation: 18243

Picasso has a thing called Target to intercept a Bitmap as it comes in.

class MyTarget implements Target {

    private ImageView imageView;

    public MyTarget(ImageView imageView) {
        this.imageView = imageView;
    }

    @Override
    public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
        this.imageView.setImageBitmap(bitmap);
    }

}

With this you can do:

Picasso.with(context).load(url).into(new MyTarget(imageView));

And set the Bitmap to an ImageView there (in the Target).

Upvotes: 2

Related Questions