Je cherche à redimmensionner une ImageIcon grâce au code suivant sans succès:
ImageIcon i = new ImageIcon(Toolkit.getDefaultToolkit().getImage("clubanana.jpg")); ... jpimg.add(new JLabel(i));
et puis plus loin je veux afficher la meme image mais sou forme de vignette avec :
current_img = new JButton("Thumbnail",i); i.getScaledInstance(25,25,1);
savez-vous pourquoi le compilateur me répond "cannot resolve symbolé en pointant i.
merci d'avance, blackiSS
au hazard... t'es encore dans la même méthode ? sinon c'est normal. C'est une question de portée.
Frédéric
Christophe Roudet
Essai avec ça:
/** * @param icon The image to scale. * @param ratio The desired ratio [0 - 1]. */ public static Icon createScaledIcon(ImageIcon icon, float ratio) { if ((ratio < 0) || (ratio >= 1)) { return icon; } int w = (int) (icon.getImage().getWidth(icon.getImageObserver()) * ratio); int h = (int) (icon.getImage().getHeight(icon.getImageObserver()) * ratio); return createScaledIcon(icon, w, h); }
/** * @param icon The icon to scale. * @param width The desired width. * @param height The desired height. */ public static Icon createScaledIcon(ImageIcon icon, int width, int height) { return new ImageIcon(icon.getImage().getScaledInstance(width, height, Image.SCALE_DEFAULT)); }
Christophe
"news.wanadoo.fr" wrote in message news:c7u4pt$kvt$
Bonsoir,
Je cherche à redimmensionner une ImageIcon grâce au code suivant sans succès:
ImageIcon i = new ImageIcon(Toolkit.getDefaultToolkit().getImage("clubanana.jpg")); ... jpimg.add(new JLabel(i));
et puis plus loin je veux afficher la meme image mais sou forme de vignette
avec :
current_img = new JButton("Thumbnail",i); i.getScaledInstance(25,25,1);
savez-vous pourquoi le compilateur me répond "cannot resolve symbolé en pointant i.
merci d'avance, blackiSS
Essai avec ça:
/**
* @param icon The image to scale.
* @param ratio The desired ratio [0 - 1].
*/
public static Icon createScaledIcon(ImageIcon icon, float ratio) {
if ((ratio < 0) || (ratio >= 1)) {
return icon;
}
int w = (int) (icon.getImage().getWidth(icon.getImageObserver()) *
ratio);
int h = (int) (icon.getImage().getHeight(icon.getImageObserver()) *
ratio);
return createScaledIcon(icon, w, h);
}
/**
* @param icon The icon to scale.
* @param width The desired width.
* @param height The desired height.
*/
public static Icon createScaledIcon(ImageIcon icon, int width, int
height) {
return new ImageIcon(icon.getImage().getScaledInstance(width,
height, Image.SCALE_DEFAULT));
}
Christophe
"news.wanadoo.fr" <mandone@ifrance.com> wrote in message
news:c7u4pt$kvt$1@news-reader4.wanadoo.fr...
Bonsoir,
Je cherche à redimmensionner une ImageIcon grâce au code suivant sans
succès:
ImageIcon i = new
ImageIcon(Toolkit.getDefaultToolkit().getImage("clubanana.jpg"));
...
jpimg.add(new JLabel(i));
et puis plus loin je veux afficher la meme image mais sou forme de
vignette
avec :
current_img = new JButton("Thumbnail",i);
i.getScaledInstance(25,25,1);
savez-vous pourquoi le compilateur me répond "cannot resolve symbolé en
pointant i.
/** * @param icon The image to scale. * @param ratio The desired ratio [0 - 1]. */ public static Icon createScaledIcon(ImageIcon icon, float ratio) { if ((ratio < 0) || (ratio >= 1)) { return icon; } int w = (int) (icon.getImage().getWidth(icon.getImageObserver()) * ratio); int h = (int) (icon.getImage().getHeight(icon.getImageObserver()) * ratio); return createScaledIcon(icon, w, h); }
/** * @param icon The icon to scale. * @param width The desired width. * @param height The desired height. */ public static Icon createScaledIcon(ImageIcon icon, int width, int height) { return new ImageIcon(icon.getImage().getScaledInstance(width, height, Image.SCALE_DEFAULT)); }
Christophe
"news.wanadoo.fr" wrote in message news:c7u4pt$kvt$
Bonsoir,
Je cherche à redimmensionner une ImageIcon grâce au code suivant sans succès:
ImageIcon i = new ImageIcon(Toolkit.getDefaultToolkit().getImage("clubanana.jpg")); ... jpimg.add(new JLabel(i));
et puis plus loin je veux afficher la meme image mais sou forme de vignette
avec :
current_img = new JButton("Thumbnail",i); i.getScaledInstance(25,25,1);
savez-vous pourquoi le compilateur me répond "cannot resolve symbolé en pointant i.