allora, mettendo insieme un po' di righe di codice di altri progettini:
codice:
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;
/**
*
* @author Andrea
*/
public class ImageRotate extends JFrame {
private File base_path = new File("C:/Users/Andrea/Desktop");
private File source = new File(base_path, "source.jpg");
private File dest = new File(base_path, "dest.jpg");
private JLabel show_source, show_dest;
private BufferedImage rotate(BufferedImage image, double degs) {
int width = image.getWidth(null);
int height = image.getHeight(null);
BufferedImage temp = new BufferedImage(height, width, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = temp.createGraphics();
g2.rotate(Math.toRadians(degs), height / 2, height / 2);
g2.drawImage(image, 0, 0, Color.WHITE, null);
g2.dispose();
return temp;
}
public ImageRotate() throws Exception {
BufferedImage sourceImage = ImageIO.read(source);
int sourceWidth = sourceImage.getWidth();
int sourceHeight = sourceImage.getHeight();
// Cosmetica
int frameHeight = 40+Math.max(sourceHeight, sourceWidth);
int frameWidth = 10 + Math.max(sourceHeight, sourceWidth);
// rotazione e salvataggio
BufferedImage destImage = this.rotate(sourceImage, 90);
ImageIO.write(destImage, "jpeg", dest);
// displaya video.
this.show_source = new JLabel(new ImageIcon(sourceImage));
this.show_dest = new JLabel(new ImageIcon(destImage));
JPanel showImages = new JPanel(new GridLayout(2,1));
showImages.add(show_source); showImages.add(show_dest);
this.getContentPane().add(new JScrollPane(showImages), BorderLayout.CENTER);
this.setSize(frameWidth, frameHeight);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main (String[] args) {
try {
new ImageRotate();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
questo mi fa il suo degno lavoro.