@Grab(group='com.jhlabs', module='filters', version='2.0.235') import java.awt.* import java.awt.image.* import java.io.* 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 wr = img2.getRaster() def buf = new int[4] for(int ly=0;ly<wr.getHeight();ly++){ for(int lx=0;lx<wr.getWidth();lx++){ wr.getPixel(lx, ly, buf) buf[0] = buf[1] = buf[2] = 255 buf[3] = (int)(Math.random()*0.2*255+255*0.6) wr.setPixel(lx, ly, buf) } } def gf = new GaussianFilter() gf.setRadius(5f) img = gf.filter(img, null) gf.setRadius(1f) img2 = gf.filter(img2, null) def gr = img.createGraphics() gr.drawImage(img2,0,0,null) gr.dispose() ImageIO.write(img, "png", new File("frostedglass.png"))
元画像
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment