LWJGL Display.setIcon

Started by poke1103, August 12, 2010, 21:51:43

Previous topic - Next topic

poke1103

Uh... Is there a way to load an image instead of loading a byte buffer?

Matthias

Use TWL's PNGDecoder (also available as separate JAR - see link in signature):
    Display.setIcon(new ByteBuffer[] {
        loadIcon(getClass().getResource("icon16.png")),
        loadIcon(getClass().getResource("icon32.png")),
    });

    .........

    private static ByteBuffer loadIcon(URL url) throws IOException {
        InputStream is = url.openStream();
        try {
            PNGDecoder decoder = new PNGDecoder(is);
            ByteBuffer bb = ByteBuffer.allocateDirect(decoder.getWidth()*decoder.getHeight()*4);
            decoder.decode(bb, decoder.getWidth()*4, PNGDecoder.Format.RGBA);
            bb.flip();
            return bb;
        } finally {
            is.close();
        }
    }