My java J2SE application is reading a lot of (png) images from the web and some of them use features such as a transparency color for true-color images (tRNS section) that Sun's/Oracle's PNGImageReader implementation simply ignores.
Therefore the common solution for loading via ImageIO.read(...);
does not work for me as it relies on this incomplete PNG开发者_JAVA百科ImageReader implementation.
Does anybody know a png reader implementation that can read all forms of PNG images correctly - those with color table or true-color and alpha transparency or transparent color?
As it is for a GPL project it should be a non-commercial one that can be included without licensing problems into the app.
Edit: My be this question was too specific. Therefore let be redesign my question:
Who knows alternative implementations and libraries that are able to load PNG files?
I will then test the implementations for their capabilities to load some test png images.
Edit2: The end result have to be a BufferedImage
Finally I found a suitable PNG reader which fits my needs perfectly:
Sixlegs Java PNG Decoder
Main features:
- Open Source (LGPL)
- Loads PNG correctly including alpha transparency and transparent colors
- Returns a BufferedImage
- Has no further dependencies to other libraries
- Has a very small size (46KB for the whole library).
Have you tried the Apache Commons Imaging library? The PNG support is specified as:
Supported through version 1.2/ISO/IEC standard (15948:2003). Controlling the exact format when writing is incomplete.
Being a pure Java library, it should work well on J2SE.
Use the following to acquire the image:
Toolkit.getDefaultToolkit().getImage(theFilenameOfTheImage)
Edit: If you need a BufferedImage, you can use the following:
ImageIcon iic=new ImageIcon(theFilenameOfTheImage);
BufferedImage bimg=((ToolkitImage)iic.getImage()).getBufferedImage();
It basically loads the image the same way, but the ImageIcon class is using a MediaTracker to make sure the image is fully loaded. This way, you can access the resulting BufferedImage, and it will always contain the pixmap.
精彩评论