src/org/nutz/img/Images.java
public static BufferedImage twist(Object srcIm, double twistRank, String bgColor) {
        if (twistRank <= 0) {
            twistRank = 1;
        }
        BufferedImage bufImg = read(srcIm);
        double period = R.random(0, 7) + 3;// 波形的幅度倍数，越大扭曲的程序越高，一般为3
        double phase = R.random(0, 6);// 波形的起始相位，取值区间（0-2＊PI）
        int width = bufImg.getWidth();
        int height = bufImg.getHeight();

        BufferedImage tarIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D gc = tarIm.createGraphics();
        gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        gc.setBackground(Strings.isBlank(bgColor) ? Colors.randomColor() : Colors.as(bgColor));
        gc.clearRect(0, 0, width, height);

        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                int nX = pos4twist(twistRank, phase, period, height, i, j);
                int nY = j;
                if (nX >= 0 && nX < width && nY >= 0 && nY < height) {
                    tarIm.setRGB(nX, nY, bufImg.getRGB(i, j));
                }
            }
        }
        return tarIm;
    }
public static BufferedImage twist(Object srcIm, double twistRank, String bgColor) {
        if (twistRank <= 0) {
            twistRank = 1;
        }
        BufferedImage bufImg = read(srcIm);
        double period = R.random(0, 7) + 3;// 波形的幅度倍数，越大扭曲的程序越高，一般为3
        double phase = R.random(0, 6);// 波形的起始相位，取值区间（0-2＊PI）
        int width = bufImg.getWidth();
        int height = bufImg.getHeight();

        BufferedImage tarIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D gc = tarIm.createGraphics();
        gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        gc.setBackground(Strings.isBlank(bgColor) ? Colors.randomColor() : Colors.as(bgColor));
        gc.clearRect(0, 0, width, height);

        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                int nX = pos4twist(twistRank, phase, period, height, i, j);
                int nY = j;
                if (nX >= 0 && nX < width && nY >= 0 && nY < height) {
                    tarIm.setRGB(nX, nY, bufImg.getRGB(i, j));
                }
            }
        }
        return tarIm;
    }
public static BufferedImage twist ( Object srcIm , double twistRank , String bgColor ) { if ( twistRank <= 0 ) { twistRank = 1 ; } BufferedImage bufImg = read ( srcIm ) ; double period = R . random ( 0 , 7 ) + 3 ; // 波形的幅度倍数，越大扭曲的程序越高，一般为3 double phase = R . random ( 0 , 6 ) ; // 波形的起始相位，取值区间（0-2＊PI） int width = bufImg . getWidth ( ) ; int height = bufImg . getHeight ( ) ; BufferedImage tarIm = new BufferedImage ( width , height , BufferedImage . TYPE_INT_RGB ) ; Graphics2D gc = tarIm . createGraphics ( ) ; gc . setRenderingHint ( RenderingHints . KEY_ANTIALIASING , RenderingHints . VALUE_ANTIALIAS_ON ) ; gc . setBackground ( Strings . isBlank ( bgColor ) ? Colors . randomColor ( ) : Colors . as ( bgColor ) ) ; gc . clearRect ( 0 , 0 , width , height ) ; for ( int i = 0 ; i < width ; i ++ ) { for ( int j = 0 ; j < height ; j ++ ) { int nX = pos4twist ( twistRank , phase , period , height , i , j ) ; int nY = j ; if ( nX >= 0 && nX < width && nY >= 0 && nY < height ) { tarIm . setRGB ( nX , nY , bufImg . getRGB ( i , j ) ) ; } } } return tarIm ; }
扭曲图片

@param srcIm
源图片
@param twistRank
扭曲程度，默认为1，数值越大扭曲程度越高
@param bgColor
扭曲后露出的底图填充色，一般选择要源图片的背景色
@return 被扭曲后的图片
扭曲图片