1

I have the flip left functionality down (see code below) but I can't seem to find how to do a flip right. Are the calculations similar?

Flip Left:

{
    gb.drawImage(img, 0, 0, null);
    gb.dispose();

    AffineTransform tx = new AffineTransform();
    tx.translate(img.getHeight(null) / 2, img.getWidth(null) / 2);
    tx.rotate(Math.PI / 2);

    tx.translate(-img.getHeight(null) / 2, -img.getWidth(null) / 2);
    AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);

    buffImg = op.filter(buffImg, null);
 }
millhouse
  • 9,817
  • 4
  • 32
  • 40
user2840682
  • 381
  • 2
  • 11
  • 23
  • 1
    You mean something like [this](http://stackoverflow.com/questions/20275424/rotating-image-with-affinetransform/20280225#20280225)? – MadProgrammer May 05 '15 at 00:13
  • 1
    Or something like [this](http://stackoverflow.com/questions/12824684/change-the-angle-position-of-a-drawing-with-a-algorithm-in-java/12826882#12826882) – MadProgrammer May 05 '15 at 00:18
  • Second example helped a lot! thanks @MadProgrammer – user2840682 May 05 '15 at 00:46
  • I was looking for another example which would resize the image based on the angel of rotation, when I realised that the first example actually does that – MadProgrammer May 05 '15 at 00:55

1 Answers1

0

If you want to rotate in multiples of 90 degrees left or right, you could use the AffineTransform.getQuadrantRotateInstance(int) methods instead:

AffineTransform rotateLeft = AffineTransform.getQuadrantRotateInstance(1);
AffineTransform rotateRight = AffineTransform.getQuadrantRotateInstance(-1);

There's also anchored versions:

AffineTransform rotateRightCentered = AffineTransform.getQuadrantRotateInstance(-1, centerX, centerY);

If you like to use radians, yes, it's similar. 90 degrees left is -(Math.PI / 2).

Harald K
  • 26,314
  • 7
  • 65
  • 111