我对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,任何提示,我真的非常感激。
提前谢谢。