Create resources folder
- create "res" folder via "Package Explorer".
- right click on "res" folder -> "Build Path" -> "Use as Source Folder". "res" will be root of your resource.
- create "images" folder inside "res" folder. Copy your images into this folder. Path your file becomes "/images/example.jpg".
Accessing images from the "images" folder, use this piece of code into your java source code:
String cName = "example.jpg";
String sFName = "/images/"+cName;
BufferedImage img = ImageIO.read(this.getClass().getResource(sFName));
References:
https://stackoverflow.com/questions/31152233/opening-image-asset-java-jdk-8
No comments:
Post a Comment