@Grab(group='org.codehaus.griffon', module='jsilhouette-geom', version='0.4') import java.awt.* import java.awt.image.* import java.io.* import javax.imageio.* import org.codehaus.griffon.jsilhouette.geom.* // 画像に半透明の放射ストライプを描画する def img = ImageIO.read(new File("sf2.jpg")) def img2 = new BufferedImage( img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB ) gr = img2.createGraphics() gr.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ) def radius = img.getWidth()>img.getHeight()?img.getWidth():img.getHeight() def nrays = 20 def rays = new Rays(img.getWidth()/2, img.getHeight()/2, radius, nrays ) gr.setColor(new Color((int)0x000000)) gr.fill(rays) gr.dispose() // 重ね合わせ gr = img.createGraphics() gr.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f) ) gr.drawImage(img2,0,0,null) gr.dispose() ImageIO.write(img, "png", new File("compositerays.png"))
元画像
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment