Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Maybe someone knows
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
FakeOut




PostPosted: Wed Apr 30, 2008 5:08 pm   Post subject: 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.
Sponsor
Sponsor
Sponsor
sponsor
HeavenAgain




PostPosted: Wed Apr 30, 2008 5:26 pm   Post subject: RE:Maybe someone knows

hello, and welcome to compsci!

after looking thru the api things that might be able to help you out,
Graphics2D -> drawRenderableImage() and rotate()
McKenzie




PostPosted: Wed Apr 30, 2008 9:04 pm   Post subject: 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.

code:
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()
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: