
-----------------------------------
FakeOut
Wed Apr 30, 2008 5:08 pm

Maybe someone knows
-----------------------------------
Hi I'm new here and I've got a very quick question. 
Is there any way of rotating an image in java? For example, I have a picture of a car and I want to prompt the user to enter a number between 1 and 359. The program then rotates the image by that many degrees. I just want to know because it will take way too long for me to add the rotated images one by one. 

Thanks in advance.

-----------------------------------
HeavenAgain
Wed Apr 30, 2008 5:26 pm

RE:Maybe someone knows
-----------------------------------
hello, and welcome to compsci!

after looking thru the api things that might be able to help you out, 
[url=http://java.sun.com/javase/6/docs/api/java/awt/Graphics2D.html]Graphics2D -> drawRenderableImage() and rotate()

-----------------------------------
McKenzie
Wed Apr 30, 2008 9:04 pm

Re: Maybe someone knows
-----------------------------------
HeavenAgain might be right, but when I've done it I've used AffineTransform. AffineTransform basically rotates the whole drawing context which is why I save the current settings first then reset them after. 

public void draw (Graphics g)
    {
		Graphics2D g2D = (Graphics2D)g;
	
		AffineTransform saveXform = g2D.getTransform();
		AffineTransform at = new AffineTransform();
		at.rotate(direction,posX+25,posY+25);
		g2D.transform(at);
		g2D.drawImage(shipPic,(int)posX,(int)posY,panel);
		g2D.setTransform(saveXform);
	    } // end of draw()

