Devo essere in grado di ruotare le immagini individualmente (in java). L'unica cosa che ho trovato finora è g2d.drawImage (image, affinetransform, ImageObserver). Sfortunatamente, ho bisogno di disegnare l'immagine in un punto specifico, e non c'è alcun metodo con un argomento che 1.rotini l'immagine separatamente e 2. mi permetta di impostare xey. ogni aiuto è graditoJava: Rotating Images
13
A
risposta
25
Ecco come si può fare. Questo codice presuppone l'esistenza di un'immagine tamponato chiamato 'immagine' (come dice il tuo commento)
// The required drawing location
int drawLocationX = 300;
int drawLocationY = 300;
// Rotation information
double rotationRequired = Math.toRadians (45);
double locationX = image.getWidth()/2;
double locationY = image.getHeight()/2;
AffineTransform tx = AffineTransform.getRotateInstance(rotationRequired, locationX, locationY);
AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
// Drawing the rotated image at the required drawing locations
g2d.drawImage(op.filter(image, null), drawLocationX, drawLocationY, null);
8
AffineTransform
istanze possono essere concatenate (sommati). Quindi puoi avere una trasformazione che combina lo "spostamento all'origine", la "rotazione" e lo "spostamento indietro nella posizione desiderata".
+4
+1 ['RotateApp'] (http://stackoverflow.com/a/3420651/230513) è un esempio. – trashgod
0
public static BufferedImage rotateCw(BufferedImage img)
{
int width = img.getWidth();
int height = img.getHeight();
BufferedImage newImage = new BufferedImage(height, width, img.getType());
for(int i=0 ; i < width ; i++)
for(int j=0 ; j < height ; j++)
newImage.setRGB(height-1-j, i, img.getRGB(i,j));
return newImage;
}
da https://coderanch.com/t/485958/java/Rotating-buffered-image
0
Un modo semplice per farlo senza l'uso di una tale affermazione pareggio complicato:
//Make a backup so that we can reset our graphics object after using it.
AffineTransform backup = g2d.getTransform();
//rx is the x coordinate for rotation, ry is the y coordinate for rotation, and angle
//is the angle to rotate the image. If you want to rotate around the center of an image,
//use the image's center x and y coordinates for rx and ry.
AffineTransform a = AffineTransform.getRotateInstance(angle, rx, ry);
//Set our Graphics2D object to the transform
g2d.setTransform(a);
//Draw our image like normal
g2d.drawImage(image, x, y, null);
//Reset our graphics object so we can draw with it again.
g.setTransform(backup);
Problemi correlati
- 1. Rotating BufferedImage instance
- 2. PDFTK Rotating Pages Problema
- 3. GridView auto fit images
- 4. Custom UIToolBar from Images
- 5. WPF TabItem Header Images
- 6. Google images api
- 7. JLabel images array
- 8. Base64 images to gmail
- 9. Silverstripe Images has Many
- 10. Cycle2 make images links
- 11. android sdk mancante system-images
- 12. Css/images/javascript in codeigniter
- 13. Emacs org-display-inline-images
- 14. text-align: justify and images
- 15. prevenire yeoman.io da minifying images
- 16. Core graphics images bassa qualità
- 17. Rotating object to face puntatore del mouse su mousemove
- 18. Qual è la differenza tra src = "/ images/logo.gif" e src = "images/logo.gif"?
- 19. Lazy-loading images in ListView su Android
- 20. Meteor Images, CSS, "normale" Web Service
- 21. Lazy load images per UITableViewCells da NSDocumentDirectory?
- 22. Cache images local, from google firebase storage
- 23. Come visualizzare l'anteprima di R.Drawable. * Images
- 24. Come gestire l'API docker/images/create?
- 25. Vertical Align images inside li Chrome Numero
- 26. background-image: url ("images/plaid.jpg") no-repeat; non presenterò
- 27. iOS app non retina e retina images concept
- 28. Alternativa per https://ajax.googleapis.com/ajax/services/search/images?v=1.0
- 29. come memorizzare nella cache css, images e js?
- 30. Converti lista <images> in un file video?
questo ha funzionato, grazie! – Jimmt
Perché così complesso? La trasformazione contiene sia la rotazione che la traduzione, quindi basta 'g2d.drawImage (immagine, tx, ImageObserver)' con il 'tx' dalla risposta. –
Grazie, ma taglia alcune delle immagini. – HyperNeutrino