@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 radius1 = 100 def radius2 = 30 def donut = new Donut(img.getWidth()/2, img.getHeight()/2, radius1, radius2, 2 ) gr.setColor(new Color(1F, 1F, 1F, 1F)) gr.fill(donut) // 切り取り gr.setComposite(AlphaComposite.SrcIn) gr.drawImage(img,0,0,null) gr.dispose() ImageIO.write(img2, "png", new File("donut.png"))元画像 出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment