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 edge = 4 def radius = 20 // 切り取り用角丸四角の画像を作成 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 ) gr.setColor(new Color(1F, 1F, 1F, 1F)) def rr = new RoundRectangle2D.Double( edge, edge, img.getWidth()-edge*2, img.getHeight()-edge*2, radius*2, radius*2) gr.fill(rr) // 切り取り gr.setComposite(AlphaComposite.SrcIn) gr.drawImage(img,0,0,null) gr.dispose() // 枠用の角丸四角を作成 def img3 = new BufferedImage( img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB ) gr = img3.createGraphics() gr.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ) gr.setColor(new Color((int)0xBFB8A3)) def rr2 = new RoundRectangle2D.Double( 0, 0, img.getWidth(), img.getHeight(), radius*2, radius*2) gr.fill(rr2) gr.drawImage(img2,0,0,null) gr.dispose() ImageIO.write(img3, "png", new File("roundrectedge.png"))
元画像
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment