Photoshop中图像混合模式有27种:正常、溶解、变暗、正片叠底、颜色加深、线性加深、深色、变亮、滤色、颜色减淡、线性减淡、浅色、叠加、柔光、强光、亮光、线性光、点光、实色混合、差值、排除、减去、划分、色相、饱和度、颜色、明度。本文给出Java代码实现。
公式:基色 + (混合色 * 基色) / (255 - 混合色),若为彩色图像需分别处理各个通道。
// C =MIN( A +(A×B)/(256-B),255) public BufferedImage deceaseColorCompound(final BufferedImage sourceImage, final BufferedImage targetImage) { final int width = sourceImage.getWidth() > targetImage.getWidth() ? sourceImage .getWidth() : targetImage.getWidth(); final int height = sourceImage.getHeight() > targetImage.getHeight() ? sourceImage .getHeight() : targetImage.getHeight(); final BufferedImage retImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); for (int i = 0; i < width; i++) { for (int j = 0; j < width; j++) { if(i>=sourceImage.getWidth() || j>=sourceImage.getHeight()){ if(i>=targetImage.getWidth() || j>=targetImage.getHeight()){ retImage.setRGB(i, j, 0); continue; } retImage.setRGB(i, j, targetImage.getRGB(i, j)); continue; } if(i>=targetImage.getWidth() || j>=targetImage.getHeight()){ retImage.setRGB(i, j, sourceImage.getRGB(i, j)); continue; }final int color1 = sourceImage.getRGB(i, j); final int color2 = targetImage.getRGB(i, j); final int a1 = (color1 >> 24) & 0xff; final int r1 = (color1 >> 16) & 0xff; final int g1 = (color1 >> 8) & 0xff; final int b1 = color1 & 0xff; final int a2 = (color2 >> 24) & 0xff; final int r2 = (color2 >> 16) & 0xff; final int g2 = (color2 >> 8) & 0xff; final int b2 = color2 & 0xff; final int a = deceaseColorChannel(a1, a2); final int r = deceaseColorChannel(r1, r2); final int g = deceaseColorChannel(g1, g2); final int b = deceaseColorChannel(b1, b2); final int result = (a << 24) | (r << 16) | (g << 8) | b; retImage.setRGB(i, j, result); } } return retImage; } // C =MIN( A +(A×B)/(256-B),255) private int deceaseColorChannel(final int source, final int target) { final int result = source + source * target / (256 - target); return result > 255 ? 255 : result; }
图一:
图二:
source->图一,target->图二:
source->图二,target->图一:
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于