2010-04-05

利用 Java 將圖像轉換成負片效果 (Use Java to edit an image to negative)

import java.awt.image.BufferedImage;
import java.awt.Graphics2D;

public static BufferedImage negative(BufferedImage source){
    BufferedImage out = new BufferedImage(source.getWidth(), source.getHeight(), source.getType());
    for (int i = 0; i < out.getWidth(); i++) {
        for (int j = 0; j < out.getHeight(); j++) {
            out.setRGB(i, j, (source.getRGB(i, j) ^ 0xffffff));
        }
    }
    return out;
}

修改前
before
apple.jpg

修改後
after
apple2.jpg

沒有留言 :

張貼留言