1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| public int scale(String cheminDep,String nomImageDep, int width, int height) {
int result=0;
File image1 = new File(cheminDep,nomImageDep);
// Spécifier le nom du fichier de l'image redimensionnée
String pictureName = "imageModifiée.gif";
// Mettez la dimension de la capture finale ici
Dimension finalDim = new Dimension(width,height);
try {
// L'image originale
BufferedImage img = ImageIO.read(image1);
// L'image redimensionnée
BufferedImage bufFinal = new BufferedImage(img.getWidth(),
img.getHeight(), BufferedImage.TYPE_INT_RGB);
// Redimensionnement de l'image
Graphics2D g = (Graphics2D) bufFinal.getGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(img, 0, 0, finalDim.width, finalDim.height, null);
g.dispose();
// Ecriture de l'image sur le disque
File test=new File(cheminDep,pictureName);
String format=".gif";
ImageIO.write(img, format,test);
} catch (IOException e) {
e.printStackTrace();
}
return result;
} |
Partager