2010-04-03

利用 Java 過濾圖像的色彩頻道 (Use Java to filter the color channel of an image)

import java.awt.image.BufferedImage;
import java.awt.Color;

public static BufferedImage getColorChannel(BufferedImage source, Color color){
    BufferedImage out = new BufferedImage(source.getWidth(), source.getHeight(), source.getType());
    for (int i = 0; i < out.getHeight(); i++) {
        for (int j = 0; j < out.getWidth(); j++) {
            out.setRGB(i, j, (source.getRGB(i, j) & color.getRGB()));
        }
    }
    return out;
}

修改前
before
apple.jpg

以 getColorChannel(source, Color.RED) 修改後
edit with getColorChannel(source, Color.RED)
apple1.jpg

以 getColorChannel(source, Color.GREEN) 修改後
edit with getColorChannel(source, Color.GREEN)
apple2.jpg

以 getColorChannel(source, Color.BLUE) 修改後
edit with getColorChannel(source, Color.BLUE)
apple3.jpg

沒有留言 :

張貼留言