I have created executable jar file(using Eclipse) , there are a set of image (.png) files that is to be inculded in the jar. So I have added a source folder with all the ima
The ImageIO
class has a utility method to read an InputStream
and create a BufferedImage
.
There is also a utility method to create an ImageInputStream
from an InputStream
.
ImageIO.read() takes InputStream
as a parameter so there is no meaning of casting it to ImageInputStream
.
Secondly you can not cast an InputStreamReader
object to ImageInputStream because ImageInputStream
has nothing to do with InputStreamReader
which you thought of.
Moreover getResourceAsStream() returns InputStream
. So you can directly do it like this.
InputStream resourceBuff = YourClass.class.getResourceAsStream(filepath);
BufferedImage bf = ImageIO.read(resourceBuff);