So I'm making a basic game in Java开发者_StackOverflow社区 using LWJGL. I have a .png file packed in the .jar that obviously cannot be used for textures while it's still inside the .jar. The only way I can think of getting the file out of the .jar is to create an Image object.
I've tried using getResource, but the way I currently have it set up is that it calls on the path to create a FileInputStream (I'm using a PNGDecoder class that takes the PNG's FileInputStream and directly creates the LWJGL Texture), and so it can't exactly read the .png from within the .jar.
Does anyone know how I can make the PNGDecoder happy, or have another way to convert the packed .png to a LWJGL texture?
PNGDecoder
probably accepts any InputStream
and not just a FileInputStream
. Use getClass().getResourceAsStream(...)
to directly get an InputStream
of the .png file in the .jar, without the need to extract it first.
精彩评论