Alternatives libraries for loading PNG images

拟墨画扇 提交于 2019-11-30 23:21:15

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!