private BufferedImage twistImage(BufferedImage buffImg){
Random random = new Random();
double dMultValue = random.nextInt(7) + 3;// 波形的幅度倍数,越大扭曲的程序越高,一般为3
double dPhase = random.nextInt(6);// 波形的起始相位,取值区间(0-2*PI)
BufferedImage destBi = new BufferedImage(buffImg.getWidth(), buffImg.getHeight(), BufferedImage.TYPE_INT_RGB);
for (int i = 0; i < destBi.getWidth(); i++) {
for (int j = 0; j < destBi.getHeight(); j++) {
int nOldX = getXPosition4Twist(dPhase, dMultValue, destBi.getHeight(), i, j);
int nOldY = j;
if (nOldX >= 0 && nOldX < destBi.getWidth() && nOldY >= 0 && nOldY < destBi.getHeight()) {
destBi.setRGB(nOldX, nOldY, buffImg.getRGB(i, j));
}
}
}
return destBi;
}
private int getXPosition4Twist(double dPhase, double dMultValue, int height, int xPosition, int yPosition) {
double PI = 3.1415926535897932384626433832799; // 此值越大,扭曲程度越大
double dx = (double) (PI * yPosition) / height + dPhase;
double dy = Math.sin(dx);
return xPosition + (int) (dy * dMultValue);
}
Random random = new Random();
double dMultValue = random.nextInt(7) + 3;// 波形的幅度倍数,越大扭曲的程序越高,一般为3
double dPhase = random.nextInt(6);// 波形的起始相位,取值区间(0-2*PI)
BufferedImage destBi = new BufferedImage(buffImg.getWidth(), buffImg.getHeight(), BufferedImage.TYPE_INT_RGB);
for (int i = 0; i < destBi.getWidth(); i++) {
for (int j = 0; j < destBi.getHeight(); j++) {
int nOldX = getXPosition4Twist(dPhase, dMultValue, destBi.getHeight(), i, j);
int nOldY = j;
if (nOldX >= 0 && nOldX < destBi.getWidth() && nOldY >= 0 && nOldY < destBi.getHeight()) {
destBi.setRGB(nOldX, nOldY, buffImg.getRGB(i, j));
}
}
}
return destBi;
}
private int getXPosition4Twist(double dPhase, double dMultValue, int height, int xPosition, int yPosition) {
double PI = 3.1415926535897932384626433832799; // 此值越大,扭曲程度越大
double dx = (double) (PI * yPosition) / height + dPhase;
double dy = Math.sin(dx);
return xPosition + (int) (dy * dMultValue);
}