
Color.getTransform() Method
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Alphabetical Language Reference
|
497
Hexadecimal color values are familiar to most web developers, as they are often used in
HTML tags. For example, here we use a hexadecimal number to specify the background
color of an HTML page (equal values for red and blue combine to form pink):
<BODY BGCOLOR="#FF00FF">
The hex color format used in HTML tags is, in fact, the same as the format used by
getRGB() and setRGB(). However, it’s not mandatory to use hexadecimal to interpret the
return value of getRGB(); we can also extract the individual Red, Green and Blue color
offsets from the return value of getRGB(), using the bitwise operators:
var rgb = myColorObject.getRGB();
var red = (rgb >> 16) & 0xFF; // Isolate the Red offset and assign it to red
var green = (rgb >> 8) & 0xFF; // Isolate the Green offset and assign it to green
var blue = rgb & 0xFF; // Isolate the Blue offset and assign it to blue
With the offset values separated into individual variables (one for each primary color), we
can examine and manipulate them individually as decimal numbers. However, when we
want to apply any offset value changes to a Color object, we must reassemble the offsets
into a single number, as shown in the entry for the setRGB() method.
Usage
The getRGB() and setRGB() methods are