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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| final class IConversion {
/**
* Type de compression BMP
*/
/**
* Type de compression JPEG
*/
public final static String IMAGE_TYPE_JPEG = "JPEG";
/**
* Conversion sans modification de taille d'un fichier
*
* @param fichierSource
* File
* @param fichierDestination
* File
* @param compressionType
* String
*/
public IConversion(java.io.File fichierSource,
java.io.File fichierDestination,
String compressionType) {
// buffer
java.awt.image.BufferedImage buf = null;
java.awt.image.BufferedImage bufFinal = null;
// r?cuperation de l'image dans le buffer
try {
buf = javax.imageio.ImageIO.read(fichierSource);
} catch (java.io.IOException ex) {
System.out.println("erreur");
}
System.out.println("1");
// Cr?ation du buffer final
bufFinal = new java.awt.image.BufferedImage(buf.getWidth(), buf.getHeight(),java.awt.image.BufferedImage.TYPE_INT_RGB);
System.out.println("2");
// Redimensionnement de l'image si volont?
java.awt.Graphics2D g = (java.awt.Graphics2D) bufFinal
.getGraphics();
g
.setRenderingHint(
java.awt.RenderingHints.KEY_INTERPOLATION,
java.awt.RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(buf, 0, 0, buf.getWidth(), buf.getHeight(),
null);
g.dispose();
// Ecriture du fichier destination
try {
javax.imageio.ImageIO.write(bufFinal,
compressionType, fichierDestination);
} catch (java.io.IOException e) {
e.printStackTrace();
}
}
} |
Partager