Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load bitmap with Picasso

I'm using Picasso library for load images in a viewpager, but I need to load a bitmap and Picasso accept only File variable. How can I load bitmap file using Picasso?

Bitmap imagescompress = decodeSampledBitmapFromResource(getResources(), AnohanaAdapter.imagep[position], 100, 100);

If I put imagecompress in the load function of Picasso, I've this error: Cannot resolve method 'load(android.graphics.Bitmap)'.

Actually for load images I use below code:

Picasso.with(VistaSingola.this).load(AnohanaAdapter.imagep[i]).placeholder(R.drawable.ic_launcher).error(R.drawable.error).fit().into(imageViewTouch);

But images are big and I don't want to go in OutOfMemory. Someone can help me? Please.

Thank you all help me

like image 386
Matteo Avatar asked Apr 30 '14 09:04

Matteo


1 Answers

You can use bellow code to do this

private Target target = new Target() {
      @Override
      public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { 
        //TODO: Store bitmap in global vaiable
      }
      @Override
      public void onBitmapFailed() {
      }
}

private void loadBitmap(String url) {
   Picasso.with(this).load(url).into(target);
}

@Override 
public void onDestroy() {  // could be in onPause or onStop
   Picasso.with(this).cancelRequest(target);
   super.onDestroy();
}
like image 109
Fred Avatar answered Oct 13 '22 01:10

Fred