@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.* class ShearFilter2 extends TransformFilter { float xoffset = 0.0f float yoffset = 0.0f float dx = 0.0f float rx = 0.0f float dy = 0.0f float ry = 0.0f void transformSpace(Rectangle r) { r.width = (int)r.width+Math.abs(dx) rx = dx/r.height xoffset = dx>0?-dx:0 r.height = (int)r.height+Math.abs(dy) ry = dy/r.width yoffset = dy>0?-dy:0 } void transformInverse(int x, int y, float[] out) { out[0] = x + xoffset + (y * rx) out[1] = y + yoffset + (x * ry) } } // 傾きのピクセル def dy = 30 // 画像を折り曲げたように加工する def img = ImageIO.read(new File("sf2.jpg")) // 右半分を切り取り def img2 = img.getSubimage((int)img.getWidth()/2, 0, (int)img.getWidth()/2, img.getHeight()); def imga = new BufferedImage( (int)img2.getWidth(), img2.getHeight()+Math.abs(dy), BufferedImage.TYPE_INT_ARGB ) // 左半分を切り取り def img3 = img.getSubimage(0, 0, (int)img.getWidth()/2, img.getHeight()); // 明るさを140% def ctf = new ContrastFilter() ctf.setBrightness(1.4f) img2 = ctf.filter(img2, null) // 傾ける def sf = new ShearFilter2() sf.dy = dy sf.filter(img2, imga) def imga2 = new BufferedImage( (int)img.getWidth(), imga.getHeight(), BufferedImage.TYPE_INT_ARGB ) gr = imga2.createGraphics() gr.drawImage(img3,0,dy,null) gr.drawImage(imga, img3.getWidth(),0,null) ImageIO.write(imga2, "png", new File("fold.png"))
元画像
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment