Chapter 8. Color

In this chapter, I'll cover the following topics:

  • the java.awt.Color class

  • how humans perceive light and color

  • color spaces and absolute color spaces

  • device profiles

Color is a tricky thing. If you don't believe me, try this exercise. Take a piece of construction paper in your favorite color—let's say green. Scan the paper into a computer and look at the image on the screen. It's a different green. Try looking at it on another monitor. Now print the image on a color printer. Try another color printer. Take a photograph of the paper and get the print developed. Now try it with slide film. At this point, you have six images of the original paper, probably none with the same color.

The architects of the Java 2D API realized how hard it is to deal with color, and they went to a lot of trouble to craft a correct solution. Java 2D was designed with two seemingly incompatible goals in mind:

  1. Support high-end, correct color management through the use of standard color spaces and color profiles.

  2. Make it easy to use colors without worrying about color spaces and device dependencies.

Get Java 2D Graphics now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.