Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Sams Teach Yourself Visual J++ 6 in 21 Days
(Publisher: Macmillan Computer Publishing)
Author(s): Rick Leinecker
ISBN: 0672313510
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Day 12
Images

You’ve already learned how to draw with fonts so that you can present your program using lots of text. And you’ve learned how to draw to the Java window so that your presentations can be richer and more professional looking. This chapter will teach you how to use images so that your programs can display just about anything you want.

Today you will complete these tasks:

  Understand the Image class
  Learn about Image observers
  Load images
  Learn about GIF and JPG files
  Use the PictureBox control that’s provided with Visual J++ for applications
  Draw images
  Use MediaTracker to help you wait for images to come in
  Create a clipping region before you draw
  Create borders for your images
  Invert your images

Don’t underestimate the importance of images. Up until now, you’ve probably seen Java applets on the Web doing cute little animations, but that’s not the full extent of what you’ll be using images for. Images let you load photographs and complex drawings. These allow you to present information and data that would otherwise be impossible to present in your programs.

Picture File Types: GIF and JPG

It’s a good idea to start off with a thorough understanding of the types of image files your Java applets and applications will usually be dealing with. Java will load two major types of image files. Java applications actually load more than two types, but applets on the Web load only two types; so we’ll discuss these two types in this chapter.

The two types we’ll talk about are GIF images and JPG images. GIF stands for Graphics Interchange Format. JPG (sometimes JPEG) stands for Joint Photographic Experts Group. What we’ll do now is describe the two image file formats and discuss the different advantages and disadvantages of each. Deciding which image to use in which setting will be important.

GIF Image Files

The GIF format, a creation of CompuServe, is used to store multiple bitmap images in a single file for exchange between platforms and systems. In terms of number of files in existence, GIF is perhaps the most widely used format for storing multibit graphics and image data. Even a quick peek into the graphics file section of most BBSs and Internet servers seems to prove this true. Many of these are high-quality images of people, landscapes, and cars, and astrophotographs. Most GIF files contain 16- or 256-color quality images. Grayscale images such as those produced by scanners are also commonly stored using GIF, although monochromographics such as clip art and document images rarely are—instead they’re usually stored as TIF documents.

GIF is not associated with any particular software application. GIF also is not created for any particular software application need, although most software applications that read and write graphical image data, such as paint programs, scanner and video software, and most image-file display and conversion programs, usually support GIF.

The biggest contrast between GIF and JPG is that GIF uses a lossless compression. The compression method GIF uses is LZW. This compression method does not degrade the picture quality at all. Every time you save and load the same GIF image, it is re-created with 100 percent integrity. For this reason, if you have an image that must be crisp and clear, and must be reproduced with the absolute highest quality, GIF would be your choice.

One limitation of GIF in certain circumstances is that it is limited to 256 simultaneous colors. The 256 colors, though, are selected from a palette of millions of colors, but GIF files can use only 256 of those colors at a time. For most Web applications, there’s a commonly accepted palette known as the browser-safe palette that many GIF images now use. If you use this browser-safe palette, your GIF images are almost guaranteed to have the best reproduction on systems all over the world. However, if you use some custom palette that is not easy to match on all systems, your image might not look the same and might suffer when it is displayed on another system. One big advantage of GIF files is that one GIF file can store multiple images, and the multiple images can be displayed in sequential order within a browser. These are called animated GIFs, and they are very popular on the Web.


Note:  One of the ideals in Web development are pages with sharp, clear colors for the most commonly used eight-bit color displays. Image designers are recommended to use the palette of 216 Internet-safe colors that will not change or dither when viewed cross-platform over the Internet. Almost every imaging program offers you the choice of using the Internet-safe palette.

JPG Images

JPG refers to a standards organization, a method of file compression, and sometimes a file format. The JPG file interchange format is designed to allow files containing JPG and coded data streams to be exchanged between otherwise incompatible systems and applications. For instance, a Macintosh and an IBM-compatible computer can share the same file. JPG files, unlike GIF files, use a compression method that degrades the image at least somewhat. This is called lossy compression; that is, there is a certain amount of loss every time the file is saved. For this reason, if you need an exact replication of the original image, JPG is not necessarily the choice you should make.

One advantage of JPG, however, is that even with the image degradation you get, for photographic images, you really can’t tell much of a difference. It does a great job in images of near photographic quality as opposed to those with crisp, sharp edges. JPG images are also composed of 24-bit colors. Each pixel in a JPG image can be a different color selected from a palette of millions. This is far better than the limitation of 256 colors in a GIF palette. In this case, a JPG image can consist of millions and millions of simultaneous colors.

GIF and JPG Comparisons

Let’s start by taking some examples so that we can see the difference in different types of images. First, we’ll start with an image that is simple and has clearly defined edges and colors. This image was created with PC Paint and then saved as a bmp file. It was then converted to a GIF file using a conversion program. In Figure 12.1, you can see the GIF file.


Figure 12.1  The GIF file looks identical to the bmp file that was created originally. There is no loss of image integrity..

Lots of conversion programs are available. I have a free one named ImageView that can be downloaded from www.infinitevision.net. This is a very simple program, but it’s in the public domain and can be used free of charge.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.