在 ImageView 中添加叠加图像

Adding overlay image in ImageView

我正在使用 picasso 库将图像从 url 加载到 ImageView,

Picasso.with(activityContext).load(thumbnailurl)
                .into(imageViewReference);

我可以使用 Picasso 设置 ImageView 的背景图像(不是源图像)吗?

 private Bitmap overlay(Bitmap bitmap1, Bitmap bitmap2) {
        Bitmap bmOverlay = Bitmap.createBitmap(bitmap1.getWidth(), bitmap1.getHeight(), bitmap1.getConfig());
        Canvas canvas = new Canvas(bmOverlay);
        canvas.drawBitmap(bitmap1, new Matrix(), null);
        canvas.drawBitmap(bitmap2, new Matrix(), null);
        return bmOverlay;
    }

如果你必须将一张图片设置在另一张图片上,我已经通过使用可绘制的透明图像完成了相同的任务,而另一张图片来自 sdcard,使用此代码它可以工作,你必须在此传递你的图像位图方法()...

你可以使用 picasso 的回调。但是你不能使用 setBackgroundResource 因为它总是以 int 作为参数,你将从 picasso 获得 return 中的位图。

Picasso.with(getContext()).load(url).into(new Target() {
    @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
        Drawable d = new BitmapDrawable(getResources(),bitmap);
        imageView.setBackground(d);
    }
    @Override public void onBitmapFailed(Drawable errorDrawable) { }
    @Override public void onPrepareLoad(Drawable placeHolderDrawable) { }
});