I am trying to rotate a BufferedImage and move it afterwards. If I do trans.traslate(wantedPointX, wantedPointY) either before or after the rotation I don't get the wanted result, so how can I do this?
Here is what I have tried so far:
protected void paintComponent(Graphics g) {
super.paintComponent(g);
AffineTransform trans = new AffineTransform();
try {
BufferedImage img = ImageIO.read(new File("line.png"));
trans.translate(img.getWidth() / 2, img.getHeight() / 2);
trans.rotate(Math.atan2(y, x)); //follows mouse
trans.translate(-(img.getWidth() / 2), -(img.getHeight() / 2));
//trans.moveTo(200, 200)
((Graphics2D)g).drawImage(img, trans, null);
} catch (IOException ex) {
System.err.println("error reading image");
}
}