@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 img = ImageIO.read(new File("sf2.jpg")) def dx = -20 def imga = new BufferedImage( (int)img.getWidth()+Math.abs(dx), img.getHeight(), BufferedImage.TYPE_INT_ARGB ) def sf = new ShearFilter2() sf.dx = dx sf.filter(img, imga) ImageIO.write(imga, "png", new File("hshear.png"))
元画像
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment