REVIEW - Java 2D Graphics


Java 2D Graphics


Jonathan Knudsen



O'Reilly (1999)




Peter Pilgrim


October 2000



This is a very rewarding book for the beginner and intermediate computer graphics developer.

The Java 2D API is part of the Java Media API and lays the foundation for creating high quality graphics on the Java platform. It builds upon the older weaker support for computer graphics in the early JDK releases and finally provides the functional features like geometric transformation, image processing, bi-directional text layout, anti-aliasing and compositing. The new class in the Java 2 platform called java.awt.Graphics2D, which is derived from the original java.awt.Graphics, is the workhorse of the entire API.

The difference between this O'Reilly book and the GLF book (by Vincent Hardy, published by Prentice Hall) is that the introduction to Java 2D is paced easier and slower. This is not to say that this book is a lightweight. Knudsen does not bury the reader in formal graphical, almost mathematical, concepts. In fact the first chapters starts with running the demonstration program Java2Demo.jar that is distributed with the Java 2 development toolkit, although he provides his own simple example Java 2D program. The first chapter covers the API fundamentals and also a little history of the people and companies that contributed to the specification and implementation.

Chapter two provides the big picture and the overall architecture of the API. The fundamentals of the rendering pipeline are described here, including alpha transparency, anti-aliasing and the process of rasterisation, compositing and mapping between co-ordinate space and device space. After the theoretical groundwork comes the practice. The author recognises that the first thing you are likely to attempt with the new API is perhaps draw lines, linear, or curved lines. So chapter three introduces the geometrically primitive parts of the API such as shapes, rectangles, lines, ellipses, arcs and general paths. For a graphics beginner some of the API will be a little fuzzy, he or she may not have any idea what to do with a general path, but there are source code examples of API use throughout and a thorough description.

Once the geometry has been mastered then it would be nice to paint or fill closed Graphics segments. Chapter four introduces the idea of painting and stroking graphics primitives. The API will allow you stroke any graphic shape primitives and paint any as long as they have closed paths. This simple fact is really explained and Knudsen shows how easy it is to draw a circle with a very thick dotted line in a red stroke and fill it with a yellow to green gradient.

Chapter five talks about the manipulation, rendering and compositing aspects of the API. There are four basic ways that primitives can be manipulated; transformation, scaling, compositing and rendering. Here is where it gets a bit hard for the graphics beginner. The author does a good job of explaining transformation theory without the matrix maths. Compositing is the process of combining two or more graphics primitives in distinct operations. For example to hide one behind other or to allow one show through the other.

One advantage of this book that stands out is the treatment of text graphics. Writing text output to a graphics window is so common that the Java 2D API helpfully provides several classes to help the developer. The authors describe very well what fonts and glyphs are and how they are measured and how text is drawn and also how styles are applied. The author gets under the teeth of the API to shows the reader how to iterate through all the characters in a text string. (Remember all strings are Unicode in Java.) Finally graphics can be embedded in the graphics text primitives and also since it is a primitive it can be transformed by rotating, scaling or shearing and composited like all the other primitives. There is a lot to cover about text so the author sensibly splits the discussion into two chapters.

Chapter eight is reserved for colour which is extremely important for Java 2D API. The final chapters cover advanced topics such buffered images, image manipulation operations, reading and writing JPEG images, rasterisation, printing and performance.

This is a very rewarding book for the beginner and intermediate computer graphics developer.

Book cover image courtesy of Open Library.

Your Privacy

By clicking "Accept All Cookies" you agree ACCU can store cookies on your device and disclose information in accordance with our Privacy Policy and Cookie Policy.

By clicking "Share IP Address" you agree ACCU can forward your IP address to third-party sites to enhance the information presented on the site, and that these sites may store cookies on your device.