Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load a bitmap into an image-view with Picasso

Yes, I am using Picasso to load a bitmap. The reason is I am decoding URIs in one part of my adapter, and loading bitmaps in another, and I read here that

You should always call Picasso, even if your URL is null. This way it knows that the image view was recycled.

So I tried this....

Bitmap bitMap;

...

Picasso.with(getContext())
    .load(bitMap)
    .into(imageView);

But I got this error

cannot resolve method 'load(android.graphics.Bitmap)'

like image 374
the_prole Avatar asked Dec 03 '15 08:12

the_prole


People also ask

How do 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.

Which is better glide or Picasso?

Glide is faster and the results of Picasso and Coil are similar. But what about when we are loading from the cache. As you can see in the images below we have the best times for Glide in most of the cases.


1 Answers

You cant put Bitmap for load method of Picasso. You can use only uri , file , url path and int resource id.

If You are downloading image from url then you can do like as below code:

String url = "your_url";
Picasso.with(context).load(url)
    .placeholder(R.drawable.any_drawable)
    .error(R.drawable.anydrawable).into(your_imageView);

For other resource its same, only load method parameter would gets changed depending on the resource you are using.

like image 149
Pankaj Avatar answered Oct 21 '22 02:10

Pankaj