如何使用 Picasso 将位图加载到图像视图中

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

是的,我正在使用 Picasso 加载位图。原因是我在我的适配器的一部分解码 URI,并在另一部分加载位图,我读到 here

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

所以我试了一下....

Bitmap bitMap;

...

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

但是我得到了这个错误

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

您不能为 Picasso 的加载方法放置位图。您只能使用 uri , file , url path and int resource id

如果您是从 url 下载图像,那么您可以像下面的代码那样做:

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

对于其他相同的资源,只有 load 方法 parameter 会根据您使用的 resource 进行更改。