所以我基本上不了解 PorterDuff 及其各种模式。我有两张我想组合的图像,一张是航拍图像,另一张是要覆盖在航拍上的 alpha 蒙版,因此只有某些部分可以显示出来。我目前有一个系统,我可以在其中正确地将蒙版叠加到只有它通过的其他图像上,但问题是在这种情况下我必须有背景颜色并且我需要它是透明的。(类似于这里的问题Efficient Bitmap masking with black and white alpha mask in Android)
Bitmap thumbnail = Bitmap.createBitmap(mThumbnailSize, mThumbnailSize, Config.ARGB_8888);
Canvas canvas = new Canvas(thumbnail);
Paint paint = new Paint();
paint.setFilterBitmap(true);
canvas.drawColor(Color.TRANSPARENT);
canvas.drawBitmap(aerial, transformation, paint);
paint = new Paint();
paint.setFilterBitmap(true);
paint.setColorFilter(new PorterDuffColorFilter(Color.WHITE,PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(overlay, transformation, paint);
我觉得我已经尝试了 ColorFilter、XferMode 的每一种组合,甚至以相反的顺序绘制图像,但似乎没有任何效果。我觉得我完全误解了 PorterDuff 模式的工作原理(基于我的很多信息http://ssp.impulsetrain.com/porterduff.html)。
如果有人对如何实现这一点有任何见解,我应该使用什么 PorterDuff 模式,我应该使用 ColorFilter 还是 XferMode,任何事情我都会非常感激。
提前致谢