import java.io.* import java.awt.* import java.awt.geom.* import java.awt.image.* import javax.imageio.* // 画像をタイル模様で切り取る def img = ImageIO.read(new File("sf2.jpg")) def img2 = new BufferedImage( img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB ) def gr = img2.createGraphics() // レンダリングヒントを設定 def rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON) rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY) gr.setRenderingHints(rh) def boxsize = 18 def rsize = 2 def padding = 2 def interval = boxsize + padding gr.setColor(new Color(1F, 1F, 1F, 1F)) for(int ly=0;ly<img.getHeight();ly+=interval){ for(int lx=0;lx<img.getWidth();lx+=interval){ def rr = new RoundRectangle2D.Double( lx, ly, boxsize, boxsize, rsize*2, rsize*2) gr.fill(rr) } } // 切り取り gr.setComposite(AlphaComposite.SrcIn) gr.drawImage(img,0,0,null) gr.dispose() ImageIO.write(img2, "png", new File("tile.png"))元画像 出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment