@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 wr = img2.getRaster() def buf = new int[4] def color1 = 0xfff0f0f0 def bwidth = 20 for(int ly=0;ly<img.getHeight();ly++){ if( ly%bwidth < (bwidth/2) ){ for(int lx=0;lx<img.getWidth();lx++){ wr.getPixel(lx, ly, buf) buf[0] = (color1 >> 16) & 0xff buf[1] = (color1 >> 8) & 0xff buf[2] = color1 & 0xff buf[3] = 0xff wr.setPixel(lx, ly, buf) } } } def cf = new CompositeFilter( MiscComposite.getInstance(MiscComposite.BLEND, 0.5f)) cf.filter(img2, img) ImageIO.write(img, "png", new File("hbands.png"))元画像 出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment