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
| public void setPhoto(String photo) {
txtPhoto.setText(photo);
if(txtPhoto.getText().isEmpty()==false){
img=toolkit.getImage(txtPhoto.getText());
buffinal=scale(img,panel.getWidth(),panel.getHeight());//buffinal declaré en BufferedImage
JLabel lab = new JLabel(buffinal); //probleme ICI !
panel.add(lab);
}
}
public static Image scale(Image source, int width, int height) {
/* On crée une nouvelle image aux bonnes dimensions. */
BufferedImage buf = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
/* On dessine sur le Graphics de l'image bufferisée. */
Graphics2D g = buf.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(source, 0, 0, width, height, null);
g.dispose();
/* On retourne l'image bufferisée, qui est une image. */
return buf;
} |
Partager