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 cut = 20.0 def gr = img2.createGraphics() gr.setColor(new Color(1F, 1F, 1F, 1F)) def path = new Path2D.Double() path.moveTo(cut, 0.0) path.lineTo(img.getWidth() - 1 - cut, 0.0) path.lineTo(img.getWidth() - 1, cut) path.lineTo(img.getWidth() - 1, img.getHeight() - 1 - cut) path.lineTo(img.getWidth() - 1 - cut, img.getHeight() - 1) path.lineTo(cut, img.getHeight() - 1) path.lineTo(0.0, img.getHeight() - 1 - cut) path.lineTo(0.0, cut) gr.fill(path) // 切り取り gr.setComposite(AlphaComposite.SrcIn) gr.drawImage(img,0,0,null) gr.dispose() ImageIO.write(img2, "png", new File("cutedge.png"))元画像 出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment