Affichage d'une image PNG
Bonjour tout le monde dans ma petite application, je voudrais sur un clic afficher une image préalablement stocké sur le disque dans une nouvelle fenetre. voici le bout de code
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| if(source==linespace){
String file = "espace_de_hough.png";
JFrame frame = new JFrame();
frame.setTitle("Accumulateur");
ImageIcon Imc= new ImageIcon("espace_de_hough.png");
Image imag = Imc.getImage();
frame.setSize(imag.getWidth(null), imag.getHeight(null));
Graphics g = frame.getGraphics();
Graphics2D g2 = (Graphics2D)g;
try {
g2.drawImage(imag, 0, 0, null);
frame.paintComponents(g2);
frame.paintAll(g2);
g.dispose();
g2.dispose();
frame.setVisible(true);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.print("\nOn ");
} |
la reférence de l'erreur est a cette instruction
Citation:
g2.drawImage(imag, 0, 0, null);
et voici le message d'erreur
Code:
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
| Java.lang.NullPointerException
at my.hough.packages.Paint.actionPerformed(Main.java:664)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source) |
j'aimerai bien comprendre ce qui ce passe. Merci a tous/