   [java] Image Rotation
  I want to rotate an image and store it back into the image instance. It must be simple, what am I missing?    BufferedImage image = ImageIO.read(new File("filename"));    Graphics2D g2d = image.createGraphics();    g2d.rotate(Math.toRadians(90));  // rotation occurs around 0,0, translate back into view.    g2d.translate(0, image.getHeight()/2);    image = ??? what do I do now?- Thanks   
  Are you trying to output the image to a file?  If so can you not just use a buffered writer to output the image back to the file without converting it back?I could be wrong... but I think that you can...   ;  The application is a tile playing game. I display the tile in a JLabel and you can place it on the board wherever you want. When the user wants to rotate the tile I plan to rotate the image object in my Tile class, then tell the JLabel to update.So I don't plan to ever write it to disk, I just plan to rotate the instance in the class. I'd like to just rotate it once and then paint it over and over rather than do a rotation every time I paint.I could of course store the Graphics2D rotated object, it just didn't seem as clean as replacing my existing image object.   ;  I may be way off the mark here, so I apologise in advance if I am.What happens if you try using the image instance you already have to display the rotated image since you have updated the graphics context for that image.  Basically I think when you update the graphics object, you will also be updating the image object.So, I think all you need to do is after your code simply add:ImageIcon icon = new ImageIcon(image);label.setIcon(icon); // update your JLabel to use your new imagethen repaint, etc.Hope I haven't just spouted a load of rubbish, good luck anyway!   ;  Thanks for the suggestion, but the image object doesn't seem to be updated. If the image object itself was updated I would see it get rotated over and over when the component painted itself. The code below shows how I'm currently doing it, maybe there's a better way.protected void paintComponent(Graphics g){   // rotated: 1=90 deg, 2=180 deg, 3=270 deg   if (rotated > 0) {   g2d = (Graphics2D) g;  g2d.rotate(Math.toRadians(90*rotated),0,0);  if (rotated == 1) { g2d.drawImage(image,0,-getWidth(),this);  }  else if (rotated == 2) { g2d.drawImage(image,-getHeight(),-getWidth(),this);  }  else if (rotated == 3) { g2d.drawImage(image,-getHeight(),0,this);  }   }   else {  super.paintComponent(g);   }    };  philcuk you had it right afterall, I just needed to re-arrange things:    public void rotate()    {   int width = image.getWidth();   int height = image.getHeight();   AffineTransform at = new AffineTransform();   BufferedImage newImage = new BufferedImage(2*width, 2*image.getHeight(), image.getType());   at.translate(image.getWidth(),0);   g2d = (Graphics2D) newImage.getGraphics();   g2d.drawImage(image,at, null);   image = newImage;    AffineTransform at2 = new AffineTransform();   newImage = new BufferedImage(width, height, image.getType());   at2.rotate(Math.toRadians(90),width, 0);   g2d = (Graphics2D) newImage.getGraphics();   g2d.drawImage(image,at2, null);   image = newImage;   setIcon(getImageIcon());    }Thanks for spurring me into thinking from another angle.   ;  I'm relieved I didn't just give you some really bad advice :)Glad it worked out!   ;  Thanks for taking the time to reply, hope I can return the favor one day.   