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() gr.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ) def radius = 20 gr.setColor(new Color(1F, 1F, 1F, 1F)) for(int lx=0;lx<img.getWidth();lx+=radius*2){ def rr = new Ellipse2D.Double( lx, 0, radius*2, radius*2) gr.fill(rr) } def rect = new Rectangle2D.Double( 0, radius, img.getWidth(), img.getHeight() - radius) gr.fill(rect) // 切り取り gr.setComposite(AlphaComposite.SrcIn) gr.drawImage(img,0,0,null) gr.dispose() ImageIO.write(img2, "png", new File("cuttopcircles.png"))
元画像
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment