Java 类org.newdawn.slick.opengl.PNGDecoder 实例源码

项目:Artificial-Life-Evolution-Simulator    文件:Start.java   
private static ByteBuffer loadIcon(String path) throws IOException {

    InputStream inputStream = new FileInputStream(path);
    try {
        PNGDecoder decoder = new PNGDecoder(inputStream);
        ByteBuffer bytebuf = ByteBuffer.allocateDirect(decoder.getWidth()*decoder.getHeight()*4);
        decoder.decode(bytebuf, decoder.getWidth()*4, PNGDecoder.RGBA);
        bytebuf.flip();
        return bytebuf;
    } finally {
        inputStream.close();
    }
}
项目:sandbox    文件:DisplayManager.java   
private ByteBuffer loadIcon(String file) {
    try {
        InputStream is = Loader.getResourceAsStream(file);
        PNGDecoder decoder = new PNGDecoder(is);

        ByteBuffer bb = ByteBuffer.allocateDirect(decoder.getWidth() * decoder.getHeight() * 4);
        decoder.decode(bb, decoder.getWidth() * 4, PNGDecoder.RGBA);
        bb.flip();
        is.close();
        return bb;
    } catch (Exception e) {
        Log.stackTrace(e);
        return null;
    }
}