@Grab(group='org.codehaus.griffon', module='jsilhouette-geom', version='0.4') import java.awt.* import java.awt.image.* import java.io.* import javax.imageio.* import org.codehaus.griffon.jsilhouette.geom.* // 画像を上方向タブ形に切り取る 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 = 40 def mrr = new MultiRoundRectangle(0, 0, img.getWidth(), img.getHeight(), radius, radius, 0, 0 ) gr.setColor(new Color(1F, 1F, 1F, 1F)) gr.fill(mrr) // 切り取り gr.setComposite(AlphaComposite.SrcIn) gr.drawImage(img,0,0,null) gr.dispose() ImageIO.write(img2, "png", new File("cuttoptab.png"))
元画像
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment