png : Java Glossary

go to home page P words local find full screen, hide local find menu Google search web for more information on this topic jump to foot of page translate this page with Babelfish 2008-08-03 by Roedy Green ©1996-2009 Canadian Mind Products
index page for letter ⇒ punctuation 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 (all)
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. Firefox and Mozilla, which are derived from Netscape, also properly support *.png. Unlike *.gif files, there were never any 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. *.pngs use varying degrees of alpha channel transparency to get this effect.
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 with alpha transparency

You might use browsershots to check out PNG support in various browsers by looking at the renderings of this page http://mindprod.com/jgloss/png.html at http://browsershots.org.

*.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.

Unfortunately Java Web Start in JDK 1.5 and earlier does not support *.png files for the jnlp <icon image, just *.gif and *.jpg. Support for arrived with JDK 1.6.

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 and 6.0 do not show it at all. IE can handle some transparent backgrounds but not others. Netscape 4.79 shows it with a purple background. Netscape 8.0+ shows it correctly. Opera, Mozilla, Sea Monkey and Firefox display it correctly. See Masker for details. 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 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.

Transparency Woes

When you produce ImageIO png images with transparency, Internet Explorer 5 and 6 do not render them properly, (though Internet Explorer 7+ will) however, I have heard that rendering them with palette mode creates images that IE will render correctly. PNG supports two different schemes for doing transparency.
  1. Proper: aka alpha-channel, aka translucent, aka undoctored. It uses with an 8-bit alpha channel. Each pixel can then have 256 different degrees of transparency.
  2. Mickey Mouse: aka binary transparency, aka indexed, aka doctored. It mimics the way gif handles transparency. It steals one colour from the palette map to be the transparent colour. So either a pixel is 100% transparent or 100% opaque.
IE 5 and 6 do not support the proper format, only the Mickey Mouse one. The doctoring process described in the Masker utility documentation, converts a properly formed png to a Mickey Mouse format.

You can see if your browser displays both styles of PNG image correctly:

Proper alpha channel (png undoctored):email undoctored munged email image
Mickey Mouse (png doctored):email doctored munged email image
gif doctored: gif doctored munged email image
You might use browsershots to check out PNG transparency support in various browsers by looking at the renderings of this page http://mindprod.com/jgloss/png.html at http://browsershots.org.

Generating PNG Images Programmatically

Here is the code for a program to draw a simple image, then save it as a *.png file.

There are also animated PNGs that work much like animated GIFs called Animated PNG, or APNG. It supports 24-bit colour and 8-bit alpha transparency. Opera 9.5+ and Firefox 3.0+ support it. IE, Safari, Flock and Sea Monkey do not support it. They just display the first frame.

Learning More

book cover recommend book⇒PNG: The Definitive Guide
 paperback
ISBN13:978-1-56592-542-7impressioncounter
ISBN10:1-56592-542-4impressioncounter
publisher:O’Reilly recommended
published:1999-06-01
by:Greg Roelofs
More than you wanted to know about *.png image format. Available to browse free as an ebook.
UK flag abe books.co.uk abe books.ca Canadian flag
UK flag amazon.co.uk. amazon.ca. Canadian flag
German flag abe books.de chapters.indigo.ca. Canadian flag
German flag amazon.de. abe books.com American flag
French flag abe books.fr amazon.com. American flag
French flag amazon.fr. barnes and noble.com American flag
Italian flag abe books.it powells.com American flag
Spanish flag iberlibro.com download o’reilly safari American flag
abe books anz Australian flag

CMP homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.58]
You are visitor number 23,890.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/png.html J:\mindprod\jgloss\png.html