Java Graphics  «Prev 

Understanding images using the Java AWT

It is very important for you to select the proper image format when preparing images for use in an applet. Photographic images should be stored in the JPEG image format, while most other images should be stored in the GIF format.
Adhering to this rule helps keep image sizes down to a minimum. This is critical to the performance of an applet since images are typically downloaded over a low bandwidth Internet connection.
You should also take the size of images into consideration since large images can take up significantly more space, and therefore take longer to transfer over an Internet connection.
Images are certainly a compelling way to communicate with the user, you just have to use them wisely in applets since bandwidth is such a big issue.

Buffered Images

Java 2D introduces a new java.awt.Image subclass, java.awt.image.BufferedImage.
BufferedImage represents image data that is present in memory, unlike Image, which typically represents streaming image data being transferred over a network. Java 2D also provides powerful image-processing classes that operate on BufferedImage objects and are much simpler to use than the ImageFilter class of Java 1.0.
Java knows how to read images in commonly used formats from files and URLs. You can use the getImage() method of either Applet() or Toolkit to retrieve an Image, but the image data may not have been fully read when the method returns. If you want to ensure that the image is fully loaded, you have to use a java.awt.MediaTracker. Note also that both of these methods return read-only Image objects, rather than read/write BufferedImage objects.
If you are writing a Swing application, an easy way to load an image is with the javax.swing.ImageIcon class. This class automatically waits until the image is fully loaded. For example:

Image myimage = new javax.swing.ImageIcon("myimage.gif").getImage();

As useful as ImageIcon is, its getImage() method still returns an Image object, not a BufferedImage object.