Java GUI gif89a Front-End
M. Gallant 01/12/98
Overview:
The Java programming language has good capability for graphics
rendering and image manipulation. The example below shows how
to design a Java GUI "front-end" interface to an already existing
native application. Gif images with transparency GIF89a are
ubiquituous on the Internet, and there are several large applications
as well as small utilities that achieve this. One of the most popular
utilities for both the Windows/DOS and UNIX platforms is the the utility
giftrans.exe
which has a command line interface. It is desirable to be able to
pick and preview any color in an image by mouse-clicking before invoking
the file conversion. The Java standalone application below, which requires JDK1.1,
changeIm.java,
achieves this by:
- Setting up a frame with a subclassed Canvas object to hold images
- Dynamically adjusting the Frame size to match any gif image loaded
- Adjusting the displayed image with the selected transparency color
- Reporting the selected transparent color to the standard System.out
- Launching giftrans.exe to save the image with selected transparency.
Details:
The image above shows the interface on a Win95 platform. Component layout in
the Frame is the default borderLayout and the CENTER component is the
subclassed Canvas object onto which is painted the loaded images. The SOUTH
component is actually a 2X2 panel. Note that a
new Canvas object is explicitly created for each new image loaded. This requires
removeing the previous Canvas object from the Frame container, and adding
the newly instantiated Canvas object and repacking the Frame to achieve
proper updating. This is achieved in the actionPerformed event handler.
Since this application calls another process (giftrans.exe), users must modify
the source code to indicate the correct path to that native application (specified
in the encodeSave() method). giftrans will look for the file in the same directory
as the Java class file and will save the selected transparency version with a T
prepended to the original filename in the same directory.
The Java application demonstrates several AWT1.1 event handling procedures and
pixel grabbing techniques. Some code involving
gifencoder
(which is included in the Java code, but commented out) may be of interest.
gifencoder does NOT support gif89a generation presently. For a BMP
reader and BMP-to-gif utility and more on gifencoder, see
Peter van der Linden's page.
Configuration:
To use changeIm first place the changeIm.java file in its own
directory, adjust the path to giftrans.exe in the java code as indicated above,
recompile it with JDK1.1+ (this generates two bytecode class files)
and then launch the java application with:
java changeIm yourowngifile.gif
A typical System.out display (a DOS window on Win95) shows the selected
transparency color which is updated with each mouse-click.
Go Home ET