Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Help rotating a BufferedImage

807605Oct 9 2007 — edited Oct 10 2007
Hello..

Im having troubles rotating a bufferedImage. I use this code:
    public void rotarDer(){
        
        AffineTransform aff = AffineTransform.getRotateInstance(this.info.getRotacion(),this.info.getPosX(),this.info.getPosY());
        AffineTransformOp op = new AffineTransformOp(aff,null);
        this.info.setImagen(op.filter(this.info.getImagen(),null));
        this.info.setAngulo(-this.info.getRotacion());
        
    }
Its a system that redraws itself many times each second... it is something like a gravity simulator and the problem comes when i want to rotate the ship (it is a small ship that is influenced by gravity)... when i do rotate, the image distorts and if i keep rotating, java is left without heap space and the program crashes.

The code that paints the whole thing is:
    protected void paintComponent(Graphics g){
        
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        if(this.nave!=null){
            g2.drawImage(this.nave.info.getImagen(),null,(int)this.nave.info.getPosX(),(int)this.nave.info.getPosY());
        }
Ive really tried to do many things but none of them seems to work.

I tried to do all this without the affinetransformop and just rotate the affinetransform, then just apply it when painting the ship.. but then the gravity gets messed up... instead of falling down, the ship would start to go to one side or the other... i know that its because the affinetransform changed the coordinate system but i didnt know how to prevent that.

Any help would be REALLY REALLY appreciated..
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 7 2007
Added on Oct 9 2007
1 comment
124 views