@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 radius = 20.0 def gr = img2.createGraphics() gr.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ) gr.setColor(new Color(1F, 1F, 1F, 1F)) def rr1 = new Ellipse2D.Double( -radius, -radius, radius*2, radius*2) gr.fill(rr1) def rr2 = new Ellipse2D.Double( img.getWidth()-radius, -radius, radius*2, radius*2) gr.fill(rr2) def rr3 = new Ellipse2D.Double( -radius, img.getHeight()-radius, radius*2, radius*2) gr.fill(rr3) def rr4 = new Ellipse2D.Double( img.getWidth()-radius, img.getHeight()-radius, radius*2, radius*2) gr.fill(rr4) gr.dispose() def iaf = new InvertAlphaFilter() img2 = iaf.filter(img2, null) gr = img2.createGraphics() // 切り取り gr.setComposite(AlphaComposite.SrcIn) gr.drawImage(img,0,0,null) gr.dispose() ImageIO.write(img2, "png", new File("indentedcorner.png"))
元画像
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment