Ciao ragazzi, sto diventando matto per ridimensionare un immagine. Ho visto vari codici in rete ma da tutti ottengo un file di 0 byte...Posto l'ultimo metodo che stavo provando
codice:
public void resizeImg(String savePath, double percent ) {
try {
File fileName = new File(file.getAbsolutePath());
System.out.println(file.getAbsolutePath()); // il nome file lo stampa correttamente
BufferedImage bufImg = ImageIO.read(fileName);
double sc = percent / 100;
AffineTransform tx = new AffineTransform();
tx.scale(sc,sc);
AffineTransformOp op = new AffineTransformOp(tx, null);
bufImg = op.filter(bufImg, null);
File outputFile = new File(savePath);
ImageIO.write(bufImg,getExtension(),outputFile);
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Impossible to resize " + file.getName() + "!", "Error Message", JOptionPane.ERROR_MESSAGE);
}
}
dove sbaglio?..esiste un tutorial in rete che spiega come effettuare tale operazione?
grazie
n.b. file è una variabile di classe
getExtensione è un metodo che prende l'estensione di file