Y at-il un moyen de plier un BufferedImage
en Java?Comment faire pour plier une image dans Java
Je pensais que si je recadre l'image en plus petits morceaux et que je la fais pivoter, alors je plierais essentiellement l'image, mais cela ne semble pas fonctionner.
Voici la méthode que je crée:
/**
* 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);
}
Ceci est l'image originale:
Et ceci est le résultat de cette getBentImage(image, 200, 220, Math.toRadians(1))
:
Je me attendais quelque chose de plus proche de:
Toutes les idées sur la façon de mettre en œuvre en fait une méthode getBentImage()
?
On ne sait pas vraiment ce que vous entendez par "plier". Veuillez fournir une définition précise de la transformation que vous essayez d'appliquer. –
@AndyTurner ne pas les images ci-dessous l'expliquer? –
Non, c'est pourquoi j'ai demandé. Quels sont les paramètres de la déformation? Que signifient le point de départ, le point final et les paramètres radians? Par exemple, vous passez en 1 radian comme paramètre, mais rien n'a pivoté de 57 degrés. A quoi ressemblerait-il si vous "pliez" une grille rectangulaire? –