0

So I've got this class that handles a BufferedImage:

public class Entity {

private BufferedImage sprite;

private final AffineTransform at;

public Entity(String imageFileName, int x, int y) {
    sprite = null;
    try {
        this.sprite = ImageIO.read(new File(imageFileName));
    } catch (IOException ex) {
        System.out.println(ex.getMessage());
    }
    at = new AffineTransform();
    at.translate(x, y);
}

public void draw(Graphics2D g) {
    g.drawImage(sprite, at, null);
}

public void rotate(double radians) {
    at.rotate(radians);
}

public void move(int dx, int dy) {
    at.translate(dx, dy);
}
    ...

However, the rotate function isn't behaving how I want it to; I want it just to rotate the image in place, keeping all other data about the image the same. I've seen the other questions on this topic, but they don't have the same question I do. Thank you!

Tetramputechture
  • 2,911
  • 2
  • 33
  • 48
  • 1
    For [example](http://stackoverflow.com/questions/15779877/rotate-bufferedimage-inside-jpanel/15780090#15780090), [example](http://stackoverflow.com/questions/20367149/how-to-use-affinetransform-quadrantrotate-to-rotate-a-bitmap/20368979#20368979) and [example](http://stackoverflow.com/questions/21841582/getting-the-right-image-observer-for-rotating-an-image/21841683#21841683) – MadProgrammer Feb 09 '15 at 03:33
  • Basically, you need to set a anchor point around which the `Graphics` context will be rotated... – MadProgrammer Feb 09 '15 at 03:34
  • This was marked as a duplicate, but I don't understand the answer of that question, so that's why I asked. @MadProgrammer – Tetramputechture Feb 09 '15 at 03:37
  • Basically, you need to supply a anchor point around which the `Graphics` will be rotated, in the duplicate answer, this `at.quadrantRotate(quad, img.getWidth() / 2, img.getHeight() / 2);` is what's important (you can use `at.rotate` instead, but the basic requirements are the same) – MadProgrammer Feb 09 '15 at 03:39

0 Answers0