2010-04-02

利用 Java 改變圖像的闊及高 (Use Java to edit an image width and height)

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

public static BufferedImage resize(BufferedImage source, int width, int height){
    BufferedImage out = new BufferedImage(width, height, source.getType());
    Graphics2D g2d = out.createGraphics();
    g2d.drawImage(source, 0, 0, width, height, null);
    g2d.dispose();
    return out;
}

修改前
before
apple.jpg

以 resize(source, 200, 200) 修改後
edit with resize(source, 200, 200)
apple2.jpg

沒有留言 :

張貼留言