0

I've so far been using the

Graphics2D.rotate(Math.toRadians(-1), newImage.getWidth() / 2, newImage.getHeight() / 2);

to rotate an image for an OMR Application. The result is a rotated but blurred image. Also I doubt this rotates the image about its centre. How do i specify a specific pixel-position as the centre of rotation?

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
Coder
  • 29
  • 5
  • 1
    The second parameters are the x/y position to rotate about. Personally, I use an `AffineTransformation` instead, something line [this](http://stackoverflow.com/questions/14884480/rotate-an-image-in-java-by-the-specified-angle/14885645#14885645) for example – MadProgrammer Mar 24 '13 at 03:19

1 Answers1

2

I doubt this rotates the image about its centre

You're correct, you would need

g2.rotate(Math.toRadians(-1), (newImage.getWidth() / 2) + 1, (newImage.getHeight() / 2) + 1);

Because of the fact, that co-ordinates start at the top left-hand corner location 0, 0, (rather than 1, 1), you need to add 1 to each of the divided widths to get the center.

How do i specify a specific pixel-position as the centre of rotation?

As @MadProgrammer said in his comment, the x and y parameters are the 2nd and 3rd arguments in rotate, so these are the pixel positions in relation to the Image.

Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • 2
    Could u pls tell what's the significance of adding 1 here? How do i specify the pixel position, say (p,q)? – Coder Mar 24 '13 at 03:21