rotating an image

Im making a blackjack game and for the double function i need the card image to be rotated 90 degrees.

But I have rarely worked with graphics so I need some help.

I have found this code on a site:

Graphics2D g2d = (Graphics2D)g;

// Move the origin to the center of the circle.

// g2d.translate(300, 270);

// Rotate the coordinate system around current

// origin, which is at the center of the circle.

g2d.rotate(Math.PI/8.0);

g2d.drawString("Javaaaaaaaaaaaa", 0, 0);

This draws the string Javaaa all over the place. Obviously not what i want. It should simply draw it once 90 degrees turned.

Tips, advice or code would be very appreciated.

[865 byte] By [Bhalosa] at [2007-11-27 9:02:49]
# 1

I've once did something similar, and I used the next instructions, and worked

Having the image obj, in this case 2gd

2gd.translate(0, IMG_HEIGHT);

2gd.rotate(-Math.toRadians(90));

...

Do the printing

...

2gd.rotate(Math.toRadians(90));

2gd.translate(0, -IMG_HEIGHT);

Hope that helps a somehow.

@lphazygmaa at 2007-7-12 21:33:59 > top of Java-index,Java Essentials,Java Programming...
# 2

it most definatly does. Thank you.

One more question though. I use the following line of code to draw the image.

g2d.drawImage(kaartAfbeelding.getImage(), 50, 50, 60, 75, null);

The coords i gave no longer seem to work now that its rotated. It ends up at a different location.

Do you know why?

Bhalosa at 2007-7-12 21:33:59 > top of Java-index,Java Essentials,Java Programming...
# 3

If I remember well, since it is rotated, the direction of the printing varies because

of the angle, so if I'm not wrong, this might be the explanation.

Before rotating, your origin was (case A)

(0,0)

__

|

|

|

After rotated, your origin, now is (case B)

|

|

|__

(0,0)

And the drawImage is always considering the first case.

Hope it helps, if you find I was wrong and get the answer, please reply back.

@lphazygmaa at 2007-7-12 21:33:59 > top of Java-index,Java Essentials,Java Programming...