如何将颜色过滤器应用于Java中的BufferedImage(或Graphics2D)。与Photoshop中具有叠加类型'颜色'。
的图层功能相同我尝试用AlphaComposite绘画,但它不一样:)
答案 0 :(得分:0)
我确信我提供的任何内容都不会与Photoshop的复杂性相匹配,但至少,您可以使用RGBImageFilter来修改灰度图像,以更改每个像素的一个或多个RGB组件:
int redIncrement = 0;
int greenIncrement = 0;
int blueIncrement = -64;
ImageFilter filter = new RGBImageFilter() {
@Override
public int filterRGB(int x,
int y,
int rgb) {
int alpha = (rgb & 0xff000000);
int red = (rgb & 0xff0000) >> 16;
int green = (rgb & 0x00ff00) >> 8;
int blue = (rgb & 0x0000ff);
red = Math.max(0, Math.min(0xff, red + redIncrement));
green = Math.max(0, Math.min(0xff, green + greenIncrement));
blue = Math.max(0, Math.min(0xff, blue + blueIncrement));
return alpha | (red << 16) | (green << 8) | blue;
}
};
Image filteredImage = Toolkit.getDefaultToolkit().createImage(
new FilteredImageSource(image.getSource(), filter));