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 64 65 66 67 68 69 70
| public ImageIcon charger_image(String nomfic) {
ImageIcon retour = list_img.get( nomfic );
if(retour == null) {
try {
retour = new ImageIcon( this.getClass().getClassLoader().getResource( "img/" + nomfic ) );
list_img.put( nomfic, retour );
}catch (Exception e) {
e.printStackTrace();
}
}
return retour;
}
public ImageIcon charger_image(String image, int taille, int effet) {
String w_key = taille + "_" + SP_EFFETS[effet] + "_" + image;
BufferedImage img = list_buffimg.get( w_key );
if(img == null) {
img = new BufferedImage( taille, taille, BufferedImage.TYPE_INT_ARGB );
ImageIcon img_ico = null;
Graphics2D g2d = null;
try {
img_ico = charger_image( image );
g2d = img.createGraphics();
g2d.setRenderingHint( RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR );
if (img_ico.getIconWidth() != taille) {
Double w_rapport = (double) taille / (double) img_ico.getIconWidth();
g2d.scale( w_rapport, w_rapport );
}
g2d.drawImage( img_ico.getImage(), 0, 0, null );
switch (effet) {
case SP_ROLLOVER:
g2d.drawImage( charger_image( "32_RO2.png" ).getImage(), 0, 0, null );
break;
case SP_GRIS:
img = new ColorConvertOp( ColorSpace.getInstance( ColorSpace.CS_GRAY ), null ).filter( img,null );
break;
case SP_FLOU:
float[] flou = { 0.1f, 0.1f, 0.1f, 0.1f, 0.2f, 0.1f, 0.1f, 0.1f, 0.1f };
img = new ConvolveOp( new Kernel( 3, 3, flou ) ).filter( img, null );
break;
case SP_CLAIR:
float[] clair = { 0f, 0f, 0f, 0f, 1.2f, 0f, 0f, 0f, 0f };
img = new ConvolveOp( new Kernel( 3, 3, clair ) ).filter( img, null );
break;
case SP_SOMBRE:
float[] sombre = { 0f, 0f, 0f, 0f, 0.8f, 0f, 0f, 0f, 0f };
img = new ConvolveOp( new Kernel( 3, 3, sombre ) ).filter( img, null );
break;
default:
break;
}
list_buffimg.put( w_key, img );
g2d.dispose();
} catch (Exception e) {
e.printStackTrace();
} finally {
g2d = null;
img_ico = null;
}
}
return new ImageIcon( img );
} |
Partager