0

I have read many BufferedImage rotating posts and found that the method to rotate it is using an AffineTransform (at), and using at.rotate(double, int, int). I got this to work, and I can turn it and all but then I want to move it so it shows at a different spot on the screen. For that I used at.translate(int, int). However, the ints don't line up with the actual JFrame I'm using, and it rotates over a different point than the rotated one. How does the translate work with relation to the rotate method? Here's the code I tried using...

public void draw(Graphics2D g){
    counter++;
    g.drawImage(animation.getImage(), (int)x, (int)y, null);
    if (counter * .05 > Math.PI * 2)
        counter = 0;
    g.rotate(counter * .05, test.getWidth() / 2, test.getHeight() / 2);
    g.drawImage(test, at, null);
    g.rotate(-counter * .05, test.getWidth() / 2, test.getHeight() / 2);
}
  • You can ignore the g.drawImage(animation.getImage(), (int)x, (int)y, null); that is to draw a different picture I have. I added the rotate -amount so that it would draw the animation.getImage() at a normal angle, which is why I added the counter. – BlastMcGuirk Feb 22 '14 at 02:14
  • Where's the "at" and how is it defined? – MadProgrammer Feb 22 '14 at 02:28
  • Sorry, at is AffineTransform (described above code) and it is defined as only a new AffineTransform(), i didn't adjust anything on it. When i try to do at.translate(double, double) it rotates on a different point. – BlastMcGuirk Feb 22 '14 at 02:57
  • I think you need to work on focusing on rotating the buffered image around its won context instead of the containers context. You could generate a rotated version if the buffered image separately and then simply paint this where ever you want – MadProgrammer Feb 22 '14 at 03:20
  • 1
    1) For better help sooner, post a [MCTaRE](http://stackoverflow.com/help/mcve) (Minimal Complete Tested and Readable Example). 2) One way to get image(s) for an example is to hot-link to the images seen in [this answer](http://stackoverflow.com/a/19209651/418556). – Andrew Thompson Feb 22 '14 at 07:34

0 Answers0