import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.io.*;
import java.util.*;
import javax.imageio.*;
public class Java2DTest12
{
public static void main(String args[])
throws Exception
{
/* Java2Dで画像を荒いドットの画像に変換する */
BufferedImage img = ImageIO.read(new File("sf.jpg"));
/* 1/10の画像に変換 */
BufferedImage img2 = new BufferedImage(
img.getWidth()/10, img.getHeight()/10, BufferedImage.TYPE_INT_BGR
);
Graphics2D gr = img2.createGraphics();
gr.drawImage(img, 0, 0, img2.getWidth(), img2.getHeight(), null);
gr.dispose();
/* 元の大きさの画像に変換 */
BufferedImage img3 = new BufferedImage(
img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_BGR
);
Graphics2D gr2 = img3.createGraphics();
gr2.drawImage(img2, 0, 0, img.getWidth(), img.getHeight(), null);
gr2.dispose();
ImageIO.write(img3, "jpg", new File("sample523a.jpg"));
}
}
元画像(sf.jpg)
出力画像(sample523a.jpg)
環境
JDK6 Upadate6(JDK1.6.0_06)
No comments:
Post a Comment