Answer the question
In order to leave comments, you need to log in
How to rotate BufferedImage?
Guys how to rotate a BufferedImage? That is, I was able to rotate it, but it doesn’t look the way I would like, how can I fix it?
Here's how the image looks before the rotation:
And here's how it looks after:
Code:
@Override
public void actionPerformed(ActionEvent e) {
Image img = image.getScaledInstance(image.getWidth(), image.getHeight(), Image.SCALE_DEFAULT);
image = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.createGraphics();
//g2.translate(workSpace.getSize().width/2, workSpace.getSize().height/2);
g2.rotate(Math.toRadians(90), image.getWidth()/2, image.getHeight()/2);
workSpace.setSize(image.getWidth(), image.getHeight());
g2.drawImage(img, 0, 0, workSpace);
workSpace.repaint();
g2.dispose();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question