import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.io.*;
import java.util.*;
import javax.imageio.*;
import com.jhlabs.image.*;
public class Java2DTest61
{
public static void main(String args[])
throws Exception
{
/* 画像の端を暗くぼかす */
BufferedImage img = ImageIO.read(new File("sf.jpg"));
BufferedImage img2 = new BufferedImage(
img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB
);
/* 端を空けて白で塗りつぶし */
Graphics2D gr1 = img2.createGraphics();
gr1.setColor(new Color(1F, 1F, 1F, 1F));
Rectangle2D rr = new Rectangle2D.Double(
2.0, 2.0, img.getWidth()-4, img.getHeight()-4);
gr1.fill(rr);
gr1.dispose();
/* ぼかし */
GaussianFilter gf = new GaussianFilter(10);
BufferedImage img3 = gf.filter(img2, null);
/* 切り取り */
Graphics2D gr2 = img3.createGraphics();
gr2.setComposite(AlphaComposite.SrcIn);
gr2.drawImage(img,0,0,null);
gr2.dispose();
/* 黒色背景画像を作成 */
BufferedImage img4 = new BufferedImage(
img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB
);
FillFilter ff2 = new FillFilter(0xff000000);
BufferedImage img5 = ff2.filter(img4, null);
/* 切り取った画像と合成 */
Graphics2D gr3 = img5.createGraphics();
gr3.drawImage(img3,0,0,null);
gr3.dispose();
ImageIO.write(img5, "jpg", new File("sample710a.jpg"));
}
}
元画像(sf.jpg)
出力画像(sample710a.jpg)
関連項目
Jerry Huxtableさんのホームページ
http://www.jhlabs.com/index.html
Java Image Filtersのページ
http://www.jhlabs.com/ip/filters/
java.netでのプロジェクトページ
https://pixels.dev.java.net/
No comments:
Post a Comment