We originally used ImageIO and JAI in our software but it didn’t meet our needs and so we created our own image library, JDeli.Our PNG encoder and decoder speeds up the process of reading and writing PNGs. JDeli also lets you set a compression limit, allowing you to choose the best compression or the fastest compression.
First a quick introduction to PNGs…
What is a PNG?
PNG stands for Portable Network Graphics. It is a lossless image format popular on the world wide web because it supports transparency in browsers.
How do I read PNG Files?
ImageIO is included in the JDK (Javadoc here). Here is how to read a png file with ImageIO:
File imageFile = new File("image.png"); BufferedImage image = ImageIO.read(imageFile);
File imageFile = new File("image.png"); PngDecoder decoder = new PngDecoder(); BufferedImage image = decoder.read(imageFile);
Alternatively, you can use the raw image data:
PngDecoder decoder = new PngDecoder(); BufferedImage image = decoder.read(rawPngData);
You can find more tutorials in our series on handling common image formats in Java, JDeli and other image libraries, including how to write out PNG files in Java.
Latest posts by Bethan Palmer (see all)
- Technical knowledge we have gained in 2017 - November 1, 2017
- Business of Software days 2 and 3 – key takeaways - September 21, 2017
- My key takeaways from Josh Kaufman’s ‘The Personal MBA’ - August 30, 2017
- 5 thing I learned from reading Nathan Chan’s Foundr book - August 24, 2017
- 3 questions raised by Dan Lyons’ ‘Disrupted’ - August 9, 2017