@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 wr = img.getRaster() def img2 = new BufferedImage( img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB ) def wr2 = img2.getRaster() def buf = new int[wr.getNumDataElements()] def buf2 = new int[4] for(int ly=0;ly<wr.getHeight();ly++){ for(int lx=0;lx<wr.getWidth();lx++){ wr.getPixel(lx, ly, buf) buf2[0] = buf[0] buf2[1] = buf[1] buf2[2] = buf[2] buf2[3] = Math.min( Math.sin(Math.PI*lx/img.getWidth())*255, Math.sin(Math.PI*ly/img.getHeight())*255 ) wr2.setPixel(lx, ly, buf2) } } def gf = new GaussianFilter() gf.setRadius(5f) img = gf.filter(img, null) def gr = img.createGraphics() gr.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER) ) gr.drawImage(img2, 0, 0, null) gr.dispose() ImageIO.write(img, "png", new File("bluredge.png"))元画像 出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment