Java Glossary : PNG

CMP home Java glossary home Menu no menu Last updated 2004-06-28 by Roedy Green ©1996-2004 Canadian Mind Products

Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

You are here : home : Java Glossary : P words : PNG.

PNG
*.png (Portable Network Graphic) files are a replacement for *.gif files when you don't need animation. JPEG files have better compression for photographs but don't handle line art as well as gif and png formats. PNG have been one of the standard image formats in Netscape and Internet Explorer since 1997, though IE support is still only partial. Opera started native support with version 3.51. Apple's Quicktime supports the format. Unlike GIF files, there are no patent restrictions, and the file format is maintained in an open source environment. You can get on a mailing list if you want to be kept informed of the latest developments. One big advantage is that fades to transparent background and antialiasing look good no matter what the background colour. With GIFs, fades only work for one colour of background, usually white or black.
feature GIF JPG PNG
colour resolution 8 bits 24 bits 8, 24, or 48 bits
grey resolution 8 bits 8 bits 8 or 16 bits
transparency 1 level none 256 levels
lossy compression no yes no
lossless compression yes unused yes
patent restrictions yes no no
animation yes no no (see MNG)
flower
PNG compression uses zlib, same as the gnu gzip and Java jar utilities. On most 8-bit images, the PNG form will be about 11% smaller than the GIF form. Java 1.4.1 supports PNG officially in the Advanced Imaging Kit. You can use PNG images with Toolkit.getImage.

You can test your browser's PNG support. You should see an image of a huge spiky red flower to the right of the table above, with proper fades into the transparent background, with no white halos. IE 5.5 does not show it at all. Netscape 4.79 shows it with a purple background. Netscape 7.02 shows it correctly. Opera 7.21 shows it correctly. You can also click here and here for more tests.

The PNG file header looks like this:

PNG Header Format
Field Contents Size
signature \211PNG\r\n\032\n
i.e. hex 89504E470D0A1A0A
8-bytes
chunksize 0x0000000D 4 bytes big-endian binary
chunkid "IHDR"
i.e. hex 0x49484452
4 bytes
width   4 bytes big-endian binary
height   4 bytes big-endian binary

The ImageInfo class the CMP Business classes will give you the width and height of png images (also gif and jpg) without loading them. It just read the first few bytes of the file.


CMP logo
CMP_home
home
Canadian Mind Products CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[24.87.56.253]
Your IP:[80.134.30.163]
You are visitor number 2312.
Please send errors, omissions and suggestions
to improve this page to Roedy Green.
You can get a fresh copy of this page from: or possibly from your local J: drive mirror:
http://mindprod.com/jgloss/png.html J:\mindprod\jgloss\png.html