LWJGL Forum

Programming => OpenGL => Topic started by: Matthias on May 15, 2010, 21:09:29

Title: TWL's PNGDecoder now available as standalone JAR
Post by: Matthias on May 15, 2010, 21:09:29
The PNGDecoder from the TWL - Themable Widget Library (http://twl.l33tlabs.org/) is now available as a separate JAR.

JAR: PNGDecoder.jar (http://twl.l33tlabs.org/dist/PNGDecoder.jar)
Source: PNGDecoder.java (http://hg.l33tlabs.org/twl/file/tip/src/de/matthiasmann/twl/utils/PNGDecoder.java)

Example usage:InputStream in = new FileInputStream("white_pixel.png");
PNGDecoder decoder = new PNGDecoder(in);

System.out.println("width="+decoder.getWidth());
System.out.println("height="+decoder.getHeight());

ByteBuffer buf = ByteBuffer.allocateDirect(4*decoder.getWidth()*decoder.getHeight());
decoder.decode(buf, decoder.getWidth()*4, Format.RGBA);
buf.flip();

while(buf.hasRemaining()) {
  System.out.printf("%02X\n", buf.get() & 255);
}


Have fun :)

EDIT: The PNGDecoder has been moved into the de.matthiasmann.twl.utils package. A class in the old package is still there and forwards all methods to the new PNGDecoder.