O'Reilly logo

Java Examples in a Nutshell, 3rd Edition by David Flanagan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Image I/O

Java 1.4 introduced the Image I/O API in the javax.imageio package. This API has many complex features, but at its heart it is a facility for reading and writing image files. Java was previously able to read images, but writing image files was not something it could do. javax.imageio solves that problem, as demonstrated in Example 12-14, a utility program to generate and save PNG images that fade from opaque to transparent: these images make interesting backgrounds for web pages.[1] Default implementations of javax.imageio can read GIF, JPEG, and PNG images, and can write JPEG and PNG images. The patent covering GIF image creation has expired since Java 1.4 was released, and hopefully future releases will support GIF format as well.

Example 12-14. MakeFades.java

package je3.graphics; import java.io.*; import java.awt.*; import java.awt.image.*; /* * This program creates PNG images of the specified color that fade from fully * opaque to fully transparent. Images of this sort are useful in web design * where they can be used as background images and combined with background * colors to produce two-color fades. (IE6 does not support PNG transparency.) * * Images are produced in three sizes and with 8 directions. The images * are written into the current directory and are given names of the form: * fade-to-color-speed-direction.png * * color: the color name specified on the command line * speed: slow (1024px), medium (512px), fast(256px) * direction: a compass point: N, E, S, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required