5

I'm trying to re-size a picture from my gallery to fit an imageview and save its bitmap after the fit so I can upload it to my Parse database on the press of an "add" button. Currently, when "add" is pressed, I check if the bitmap is null, and if it isn't, convert it to a Parsefile to be saved in my Parse database. Adding to the database works (I tested this without using Picasso), but I'm not sure how to get the bitmap if I use Picasso to resize and load. I tried creating a Target and using its callbacks, but I can't use .fit() on a target. I've resorted to using a callback, but I was hoping for a better way to achieve the saving of the bitmap.

Here's what I'm doing right now, trying to get the bitmap from the imageview after it's been loaded:

if(uri != null) {
            Picasso.with(mContext).load(uri).skipMemoryCache().fit().centerCrop().into(imgPreview, new Callback() {

                @Override
                public void onSuccess() {
                    mBitmap = ((BitmapDrawable)imgPreview.getDrawable()).getBitmap();
                }

                @Override
                public void onError() {
                    // TODO Auto-generated method stub
                }
            });
}
user2858182
  • 175
  • 1
  • 7
  • possible duplicate of [Use Picasso to get a callback with a Bitmap](http://stackoverflow.com/questions/20181491/use-picasso-to-get-a-callback-with-a-bitmap) – VM4 Aug 15 '14 at 07:20
  • 3
    Yeah, I saw this answer prior to posting, but you can't use .fit() with a target. It seems that doing it this way you're only able to store the original image, but I want to be able use a callback to store the bitmap after calling .fit(). I stated this in my question: " I tried creating a Target and using its callbacks, but I can't use .fit() on a target." – user2858182 Aug 15 '14 at 07:38

1 Answers1

0

You can use a callback

 Picasso.with(context)
    .load(absolutePath)
    .fit()
    .noFade()
    .centerInside()
    .placeholder(R.drawable.image_holder)
    .memoryPolicy(MemoryPolicy.NO_CACHE)
    .into(imageView, new Callback() {
        @Override
        public void onSuccess() {
        // You can do anything here because your imageView now has the bitmap set
        }

        @Override
        public void onError() {

        }
    });
Eric Brandwein
  • 861
  • 8
  • 23
Daniel Gomez Rico
  • 15,026
  • 20
  • 92
  • 162