Android Studio中的图像混合模式(如photoshop,paint.net)?

时间:2018-08-24 01:29:36

标签: android android-bitmap porter-duff blend-mode

我正在尝试用 photoshop paint.net 的相同方式混合两个图像,并使用不同的混合模式,例如Difference, Multiply, Additive, Color Burn, Glow, etc.

我发现PorterDuff.Mode的效果很好,但是它缺乏混合效果(它只有加,乘,屏),有没有办法获得更大范围的混合模式?有没有一种方法可以编辑android.graphics.PorterDuff;库以获取更多混合模式? 有什么想法吗?

例如: THIS 变成这样: Result

这是使用btw的porterduff代码:

private static Bitmap Result(Bitmap bottomImage, Bitmap topImage){


    int sizex = bottomImage.getWidth();
    int sizey = bottomImage.getHeight();

    Paint paint = new Paint();
    Bitmap imageBitmap = Bitmap.createBitmap(sizex, sizey , Bitmap.Config.ARGB_8888);
    Canvas comboImage = new Canvas(imageBitmap);
    comboImage.drawBitmap(bottomImage, 0f, 0f, paint);;
    PorterDuff.Mode mode = PorterDuff.Mode.MULTIPLY;//Porterduff MODE
    paint.setXfermode(new PorterDuffXfermode(mode));

    Bitmap ScaledtopImage = Bitmap.createScaledBitmap(topImage, sizex, sizey, false);
    comboImage.drawBitmap(ScaledtopImage, 0f, 0f, paint);

    return imageBitmap;

}

1 个答案:

答案 0 :(得分:0)

我并不是图像处理专家,但是PorterDuff有一些混合模式,即变暗,变亮,倍增,屏幕和叠加。然后,您可以使用in,atop,xor等来获得想要的混合部分的选择。

http://ssp.impulsetrain.com/porterduff.html https://developer.android.com/reference/android/graphics/PorterDuff.Mode