Salut à tous !
J'aimerai effectuer une rotation sur une image, puis en faire un JLabel. J'ai donc le code suivant :
La méthode IHand.at(int) renvoie un objet ICard et la méthode ICard.verso() renvoie un objet Image.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public JLabel handToHiddenHand(IHand h, double sens) { int width = Card.HIDDEN_WIDTH * (h.getSize() - 1) + Card.WIDTH; BufferedImage buffer = new BufferedImage(width, Card.HEIGHT, BufferedImage.TYPE_4BYTE_ABGR); Graphics2D graph = buffer.createGraphics(); int x = 0; for (int i = 0; i < h.getSize(); i++) { try { Card c = (Card) h.at(i); graph.drawImage(c.verso(), x, 0, this); x += Card.HIDDEN_WIDTH; } catch (IOException e) { JOptionPane w = new JOptionPane(); w.showMessageDialog(this, "Fatal error during loading file.", "Error", JOptionPane.ERROR_MESSAGE); } } AffineTransform transform = AffineTransform.getRotateInstance(sens); graph.transform(transform); graph.dispose(); return new JLabel(new ImageIcon(buffer)); }
VERTICAL est un flottant valant Math.PI / 2.
Au final, le JLabel s'affiche correctement, mais il n'est pas tourné de 90°... J'ai essayé également avec la méthode Graphics.rotate, mais même résultat.
Partager