0

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");
    }
}
SgtDomo
  • 1
  • 1
  • Could you please clarify what the wanted result is? – Leon Apr 02 '17 at 17:02
  • I want to rotate the image around its center point and then move the rotated image to a specific point. I already rotated the image (as shown), but now I want to move it away from the coordinate origin. – SgtDomo Apr 02 '17 at 17:04
  • Possible duplicate of http://stackoverflow.com/questions/4918482/rotating-bufferedimage-instances – Ivan Pronin Apr 02 '17 at 17:16
  • @IvanPronin That's where I got the rotating part from. But I want to move the image afterwards, which is not discussed in this question. – SgtDomo Apr 02 '17 at 17:22

0 Answers0