How do i rotate an image in the center if itself? this code works, but it rotates the image in the top-left corner of the screen:
AffineTransform oldtrans = new AffineTransform();
AffineTransform trans = new AffineTransform();
trans.setToIdentity();
trans.rotate(Math.toRadians(angle));
trans.translate(_x-(width/2), _y-(height/2));
g.setTransform(trans);
g.drawImage(this.getImage(), (int)_x, (int)_y, (int)width, (int)height, null);
trans.setToIdentity();
g.setTransform(oldtrans);
Please help!!!
You should give two more arguments in your rotate() call:
affineTransform.rotate(Math.toRadians(angle), m_imageWidth/2, m_imageHeight/2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With