I can't load image into BufferedImage Object with new File() without full path of the image.
When i'm trying to load an image.png into BufferedImage Object with new File() I face to results:
- Success - when I write the whole path (C://Users//benja//Desktop/...) it works fine
- Fail - when i write the path of the image that i have imported into my project. Is there a way to make it work even if i'm using new File(...)?
public class PicturePanel extends JPanel {
BufferedImage image=null;
public PicturePanel() {
try {
image = ImageIO.read(new
/*Works fine with full path: */
File("C://Users//benjamin//Desktop//Pictures//whiteFish.png"));
/*fail - throw an exception: */
//image = ImageIO.read(new
File("//RandomThingsInGui/whiteFish.png"));
} catch (IOException e) { e.printStackTrace(); }
repaint();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0,0,500,250,null);
}
public static void main(String[] args) {
JFrame f = new JFrame();
f.add(new PicturePanel());
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setSize(600,400);
f.setVisible(true);
}
What i need is to know if there is a way (and how) to load the image from an imported path (I mean from inside eclipse) or when I use new File(...) I must use full path.
thanks for helpers :)