@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 imga = new BufferedImage( img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB ) def gf = new GrayscaleFilter() img = gf.filter(img, imga) img2 = new BufferedImage( img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB ) def grf = new GradientFilter( new Point(0, 0), new Point(0, img.getHeight()), (int)0xff3070a0, (int)0xffffff10, false, GradientFilter.LINEAR, GradientFilter.INT_SMOOTH) img2 = grf.filter(img2, null) CompositeFilter cf = new CompositeFilter( MiscComposite.getInstance(MiscComposite.BLEND, 0.5f)) img = cf.filter(img, img2) ImageIO.write(img, "png", new File("gradientimage.png"))元画像 出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment