This question already has an answer here:
- Java: Rotating Images 4 answers
I have managed to rotate an image 180 degrees
but wish to rotate it 90 degrees
clockwise
can someone edit my code so that it does this with explanation. Thanks.
private void rotateClockwise()
{
if(currentImage != null){
int width = currentImage.getWidth();
int height = currentImage.getHeight();
OFImage newImage = new OFImage(width, height);
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
newImage.setPixel( x, height-y-1, currentImage.getPixel(x, y));
}
}
currentImage = newImage;
imagePanel.setImage(currentImage);
frame.pack();
}
}
Use this method.
taken from my ImageTool class.
Hope it helps.
Have a look at http://docs.oracle.com/javase/tutorial/2d/index.html and http://docs.oracle.com/javase/6/docs/api/java/awt/Graphics2D.html#rotate%28double%29 aswell as this post Rotate an image in java