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 brickwidth = 20 def brickheight = 10 def padding = 2 def xinterval = brickwidth + padding def yinterval = brickheight + padding def gr = img2.createGraphics() gr.setColor(new Color(1F, 1F, 1F, 1F)) def rc = 0 for(int ly=0;ly<img.getHeight();ly+=yinterval){ for(int lx=0;lx<img.getWidth()+brickwidth;lx+=xinterval){ gr.fillRect((int)lx-(rc%2==0?0:brickwidth/2), ly, brickwidth, brickheight) } rc++; } // 切り取り gr.setComposite(AlphaComposite.SrcIn) gr.drawImage(img,0,0,null) gr.dispose() ImageIO.write(img2, "png", new File("cutbrick.png"))
元画像
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment