@Grab(group='com.jhlabs', module='filters', version='2.0.235') import java.io.* import java.awt.* import java.awt.geom.* import java.awt.image.* 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 = 100.0 def gr = img2.createGraphics() gr.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ) gr.setColor(new Color(1F, 1F, 1F, 1F)) def rr = new Ellipse2D.Double( img.getWidth()/2-radius, img.getHeight()/2-radius, radius*2, radius*2) gr.fill(rr) // 切り取り gr.setComposite(AlphaComposite.SrcIn) gr.drawImage(img,0,0,null) gr.dispose() // 明るさを50% def ctf = new ContrastFilter() ctf.setBrightness(0.5f) img = ctf.filter(img, null) // 重ね合わせ gr = img.createGraphics() gr.drawImage(img2,0,0,null) gr.dispose() ImageIO.write(img, "png", new File("ellipsespot.png"))
元画像
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment