Aide charger image avec java
Fermé
patrickjunior01
Messages postés
3
Date d'inscription
mercredi 29 juillet 2009
Statut
Membre
Dernière intervention
17 septembre 2012
-
17 sept. 2012 à 12:42
patrickjunior01 Messages postés 3 Date d'inscription mercredi 29 juillet 2009 Statut Membre Dernière intervention 17 septembre 2012 - 17 sept. 2012 à 14:00
patrickjunior01 Messages postés 3 Date d'inscription mercredi 29 juillet 2009 Statut Membre Dernière intervention 17 septembre 2012 - 17 sept. 2012 à 14:00
A voir également:
- Aide charger image avec java
- Frédéric cherche à faire le buzz sur les réseaux sociaux. il a ajouté une image de manchots sur une image de plage. retrouvez l'image originale de la plage. que cachent les manchots ? ✓ - Forum Windows
- Recherche par image - Guide
- Image iso - Guide
- Jeux java itel ✓ - Forum Jeux vidéo
- Faststone image viewer - Télécharger - Visionnage & Diaporama
1 réponse
KX
Messages postés
16668
Date d'inscription
samedi 31 mai 2008
Statut
Modérateur
Dernière intervention
17 mars 2023
3 005
Modifié par KX le 17/09/2012 à 13:04
Modifié par KX le 17/09/2012 à 13:04
"J'ai déjà essayé tous les codes possibles sur internet mais rien n'y fait."
Internet c'est vraiment n'importe quoi, ou alors la vérité est ailleurs...
Internet c'est vraiment n'importe quoi, ou alors la vérité est ailleurs...
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Test1
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.add(new JLabel(new ImageIcon("C:/test.png")));
frame.pack();
frame.setVisible(true);
}
}
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
class ImagePanel extends JPanel
{
private static final long serialVersionUID = 1;
private final BufferedImage img;
ImagePanel(String fileName) throws IOException
{
img = ImageIO.read(new File(fileName));
}
@Override
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawImage(img,0,0,null);
}
}
public class Test2
{
public static void main(String...args) throws IOException
{
JFrame frame = new JFrame();
frame.add(new ImagePanel("C:/test.png"));
frame.setSize(300,300);
frame.setVisible(true);
}
}La confiance n'exclut pas le contrôle
17 sept. 2012 à 13:03
17 sept. 2012 à 13:05
17 sept. 2012 à 14:00