0

I am using Picasso library. I know that there is a call back method if i am loading a picture from a URL into an image view. But i don't want to load into an imageview. Instead, i want save it as a bitmap. so i used below code

 Bimap bmp=Picasso.with(getActivity()).load(urlString).get();

How can i get a callback method for this to know that my image is downloaded successfully using picasso?

Dont say that null check for bitmap object. It causes error.

AtHul Antony
  • 77
  • 1
  • 11
  • 3
    Possible duplicate of [How to listen for Picasso (Android) load complete events?](http://stackoverflow.com/questions/26548660/how-to-listen-for-picasso-android-load-complete-events) – Shreyash S Sarnayak Mar 15 '17 at 16:18
  • No it is loading image in to image view. I want to get it as a bitmap. Please read my question again. – AtHul Antony Mar 15 '17 at 16:19
  • Was thinking about another answer http://stackoverflow.com/questions/38617505/picasso-load-image-into-target It does what you want plus solves you problem that you might have – X3Btel Mar 15 '17 at 16:43

2 Answers2

2

if u want to get Bitmap using picasso you have to use a Target

    private Target target = new Target() {
      @Override
      public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
          //success
          Save_bitmap(bitmap);
      }

      @Override
      public void onBitmapFailed(Drawable errorDrawable) {
      }

      @Override
      public void onPrepareLoad(Drawable placeHolderDrawable) {
      }
}

private void Laod_Image() {
   Picasso.with(this).load("Your_url").into(target);
}
rafsanahmad007
  • 23,683
  • 6
  • 47
  • 62
0

Answer from rafsanahmad007 look nice but this answer also use onDestroy method to cancel the request.

Community
  • 1
  • 1
jorgeavilae
  • 208
  • 1
  • 9