2010-04-03

利用 Java 將圖像轉換成灰度圖像 (Use Java to edit an image to grayscale)

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

public static BufferedImage grayscale(BufferedImage source){
    BufferedImage out = new BufferedImage(source.getWidth(), source.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
    Graphics2D g2d = out.createGraphics();
    g2d.drawImage(source, 0, 0, null);
    g2d.dispose();
    return out;
}

修改前
before
apple.jpg

修改後
after
apple4.jpg

沒有留言 :

張貼留言