在sRGB的色彩空间工作的帮助下,很容易实现,这是否一种方法。
考虑以下方法:
private static BufferedImage createColorFromGrayscale(BufferedImage red, BufferedImage green, BufferedImage blue){
BufferedImage base = new BufferedImage(red.getWidth(), red.getHeight(), BufferedImage.TYPE_INT_ARGB);
for(int x = 0;x < red.getWidth();x++){
for(int y = 0; y < red.getHeight(); y++){
int rgb = (red.getRGB(x, y) & 0x00FF0000) | (green.getRGB(x, y) & 0x0000FF00) | (blue.getRGB(x, y) & 0x000000FF);
base.setRGB(x, y, (rgb | 0xFF000000));
}
}
return base;
}
创建新的基础图像,我们通过使用按位AND和OR来创建格式ARGB一个4字节整数颜色被分配给基本图像创建的颜色分量。通过for循环遍历整个图像,我们可以将生成的基本图像的每个像素分别设置为每个通道的颜色。
此方法假设所有三个图像的大小相等。如果图像尺寸不相同,则必须单独处理(例如通过在输入之前拉伸图像或修改方法以接受不同尺寸的图像)。
PS:直接使用一个图像可能更有效在BufferedImage的实例作为基本图像的大的图片的时候,以节省内存...
我会尝试找出。 –