@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 wr = img.getRaster() def buf = new int[wr.getNumDataElements()] def color1 = 0x948E73 def red = (color1 >> 16) & 0xff def green = (color1 >> 8) & 0xff def blue = color1 & 0xff for(int ly=0;ly<wr.getHeight();ly++){ for(int lx=0;lx<wr.getWidth();lx++){ wr.getPixel(lx, ly, buf) def mono = (buf[0] * 77 + buf[1] * 151 + buf[2] * 28) >> 8; buf[0] = (int)(mono * red / (ly % 2 + 1) / 255) buf[1] = (int)(mono * green / (ly % 2 + 1) / 255) buf[2] = (int)(mono * blue / (ly % 2 + 1) / 255) wr.setPixel(lx, ly, buf) } } def sf = new SmearFilter() sf.setShape(SmearFilter.CROSSES) sf.setDensity(0.9f) sf.setDistance(7) sf.setScatter(0.8f) //sf.setAngle((float)30*ImageMath.PI/180) img = sf.filter(img, null) ImageIO.write(img, "png", new File("paintfabric.png"))
元画像
出力画像
動作環境
groovy 1.8.6, JDK7 update4