有沒有什麼辦法可以在Java中彎曲BufferedImage
?如何在java中彎曲圖像
我認爲,如果我將圖像裁剪成更小的部分並旋轉它們,那麼我會基本上彎曲圖像,但它似乎不起作用。
這裏是我創建的方法:
/**
* This is a recursive method that will accept an image the point where the bending will start and the point where the bending will end, as well as the angle of bending
*
* @param original:the original image
* @param startingPoint: the point where the bending should start
* @param endingPoint: the point where the bending should end
* @param radiands: the angle
* @return the bent image
*/
public static BufferedImage getBentImage(BufferedImage original, int startingPoint, int endingPoint, double radians) {
if (startingPoint >= endingPoint)
return original;
int type = BufferedImage.TYPE_INT_ARGB;
int width = original.getWidth();
int height = original.getHeight();
BufferedImage crop = original.getSubimage(0, 0, startingPoint, height);
BufferedImage crop0 = original.getSubimage(startingPoint, 0, width - startingPoint, height);
BufferedImage bendCrop = new BufferedImage(width, height, type);
BufferedImage image = new BufferedImage(width, height, type);
AffineTransform rotation = new AffineTransform();
rotation.translate(0, 0);
rotation.rotate(radians);
Graphics2D g = bendCrop.createGraphics();
g.drawImage(crop0, rotation, null);
g.dispose();
g = image.createGraphics();
g.drawImage(crop, 0, 0, null);
g.drawImage(bendCrop, startingPoint, 0, null);
g.dispose();
return getBentImage(image, startingPoint + 1, endingPoint, radians);
}
這是原始圖像:
這是該getBentImage(image, 200, 220, Math.toRadians(1))
的結果:
我期待的東西更接近:
任何想法如何真正實現一個getBentImage()
方法?
目前還不清楚你實際上「彎曲」的含義。請提供您正在嘗試應用的轉換的準確定義。 –
@AndyTurner難道他們下面的圖片就解釋了嗎? –
不,這就是我問的原因。變形的參數是什麼?起點,終點和弧度參數意味着什麼?例如,你傳入1弧度作爲參數,但沒有任何東西旋轉57度。如果你「彎曲」一個矩形網格,它會是什麼樣子? –