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 wr = img.getRaster() def wr2 = img2.getRaster() def buf = new int[4] def cx = img.getWidth()/2 def cy = img.getHeight()/2 def bwidth = 20 def minradius = 50 def ratio = 1.5 for(int ly=1;ly<wr.getHeight();ly++){ for(int lx=0;lx<wr.getWidth();lx++){ wr.getPixel(lx, ly, buf) def dr = (int)Math.floor((Math.sqrt(Math.pow(lx-cx, 2) + Math.pow(ly-cy, 2))-minradius)/bwidth)*bwidth dr = (dr<0)?0:dr buf[3] = (255-dr*ratio)<0?0:(255-dr*ratio) wr2.setPixel(lx, ly, buf) } } ImageIO.write(img2, "png", new File("gradcircleband.png"))
元画像
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment