How to load Images from a package in java -
i use load same package
image image; string img = "image.png"; imageicon = new imageicon(this.getclass().getresource(img)); image = i.getimage(); how can load image package specified images?
image image; string img = "image.png"; imageicon = new imageicon(this.getclass().getresource(img)); image = i.getimage(); suggests "image.png" resides within same package class represented this
you can paths reference resources reside within different packages
string img = "/path/to/images/image.png"; imageicon = new imageicon(this.getclass().getresource(img)); the important concept here understand path suffixed class path
personally, should using imageio on imageicon, apart supporting more formats, throws ioexception when goes wrong , guaranteed return loaded image (when successful).
see how read images more details
Comments
Post a Comment