@Grab(group='com.jhlabs', module='filters', version='2.0.235') import java.awt.* import java.awt.geom.* import java.awt.image.* import java.io.* import javax.imageio.* import com.jhlabs.composite.* import com.jhlabs.image.* // 画像を銭湯タイルのように変換する def img = ImageIO.read(new File("sf2.jpg")) def img2 = new BufferedImage( img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB ) def boxsize = 4 def rsize = 2 def padding = 1 def interval = boxsize + padding def bf = new BlockFilter() bf.setBlockSize(interval) img = bf.filter(img, null) 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) 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("tiles.png"))
元画像
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment