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 gr = img2.createGraphics() gr.setColor(new Color(1F, 1F, 1F, 1F)) def path = new Path2D.Double() // 分割数 def par = 64 // 中心x def cx = img.getWidth()/2 // 中心y def cy = img.getHeight()/2 // 半径(大) def rad1 = 90 // 半径(小) def rad2 = 80 def dr1=0 def dr2=360/(par*2) path.moveTo( (int)(cx-Math.cos(2*Math.PI*dr1/360)*rad1), (int)(cy-Math.sin(2*Math.PI*dr1/360)*rad1) ) path.lineTo( (int)(cx-Math.cos(2*Math.PI*dr2/360)*rad2), (int)(cy-Math.sin(2*Math.PI*dr2/360)*rad2) ) dr1 += 360/par dr2 += 360/par while(dr2<360){ path.lineTo( (int)(cx-Math.cos(2*Math.PI*dr1/360)*rad1), (int)(cy-Math.sin(2*Math.PI*dr1/360)*rad1) ) path.lineTo( (int)(cx-Math.cos(2*Math.PI*dr2/360)*rad2), (int)(cy-Math.sin(2*Math.PI*dr2/360)*rad2) ) dr1 += 360/par dr2 += 360/par } gr.fill(path) // 切り取り gr.setComposite(AlphaComposite.SrcIn) gr.drawImage(img,0,0,null) gr.dispose() ImageIO.write(img2, "png", new File("badge.png"))元画像 出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment