Having learned how to create and load a new bitmap, we can now explore the tools for examining the pixels of an existing bitmap.
To retrieve the complete 32-bit integer color value of any pixel in a bitmap, we use the BitmapData class's instance method getPixel32( ), which takes the following form:
theBitmapDataObject is the
BitmapData instance from which
the pixel color value will be retrieved, and
y are the
horizontal and vertical location of the pixel whose color value will
be retrieved. For example, the following code creates a blue square
bitmap, then displays the color value of its top-left pixel (i.e., the
pixel at coordinates (0, 0)):
var imgData:BitmapData = new BitmapData(20, 20, false, 0xFF0000FF); trace(imgData.getPixel32(0, 0)); // Displays: 4278190335
The pixel's color value is a large number (4278190335) because the alpha channel's value is 255, so the bits in the color value's most significant byte are all 1's:
11111111 00000000 00000000 11111111
In decimal format, the individual channels in a color value returned by getPixel32( ) are indecipherable. Hence, for debugging purposes, code such as that shown in the earlier Pixel class must be used to extract human-readable channel values from the number returned by getPixel32( ):
// Displays: A:FF R:0 G:0 B:FF trace(new Pixel(imgData.getPixel32(0, 0)));
Note that the Alpha channel value for pixels in nontransparent bitmaps is always 255, even when a different ...