| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 
 | //avec un facteur (<1 pour rétrécir, >1 pour agrandir):
public static Image scaleImage(final Image source, final double factor) {
    int width = (int) (source.getWidth(null) * factor);
    int height = (int) (source.getHeight(null) * factor);
    return scaleImage(source, width, height);
}
//avec une taille en pixels (=hauteur si portrait, largeur si paysage):
public static Image scaleImage(Image source, int size) {
    int width = source.getWidth(null);
    int height = source.getHeight(null);
    double f = 0;
    if (width < height) {//portrait
        f = (double) height / (double) width;
        width = (int) (size / f);
        height = size;
    } else {//paysage
        f = (double) width / (double) height;
        width = size;
        height = (int) (size / f);
    }
    return scaleImage(source, width, height);
} | 
Partager