我正在尝试在Android上使用类似于Multiply的混合模式将两个图像混合在一起。
// Prepare -------------------------------
// Create source images
Bitmap img1 = ...
Bitmap img2 = ...
// Create result image
Bitmap result = ...
Canvas canvas = new Canvas();
canvas.setBitmap(result);
// Get proper display reference
BitmapDrawable drawable = new BitmapDrawable(getResources(), result);
ImageView imageView = (ImageView)findViewById(R.id.imageBlend1);
imageView.setImageDrawable(drawable);
// Apply -------------------------------
// Draw base
canvas.drawBitmap(img1, 0, 0, null);
// Draw overlay
Paint paint = new Paint();
paint.setXfermode(new PorterDuffXfermode(Mode.MULTIPLY));
paint.setShader(new BitmapShader(img2, TileMode.CLAMP, TileMode.CLAMP));
canvas.drawRect(0, 0, img2.getWidth(), img2.getHeight(), paint);
这个方法可行,但我无法控制乘法的“量” - 它总是进行完整的乘法转换。理想情况下,0%的乘法将与基本图像(img1)没有任何更改相同,但100%的乘法将是我使用上面代码得到的结果。
paint.setAlpha()
对此似乎无效。是否还有其他方法来设置新“层”的透明度百分比?
附注:我猜可能有一些方法可以让这个乘法方法工作(使用
LightingColorFilter
),通过预先乘以白色并偏移颜色来实现,但这非常特定于乘法模式.. 我正在尝试找到一种方法来将透明度/%的事情应用于所有其他转换模式。