Previous Page
Next Page

Recipe 10.12. Changing Saturation

Problem

You want to change the saturation of a display object.

Solution

Use a saturation matrix and apply it with a ColorMatrixFilter object.

Discussion

You can affect saturation with the following matrix:

a  b  c  0  0
d  e  f  0  0
g  h  i  0  0
0  0  0  1  0

In the preceding matrix, you need to determine the values of a through i with the following equations, where red, blue, and green are the luminance constants and value is the saturation value:

a = (1  value) * red + value
b = (1  value) * green
c = (1  value) * blue
d = (1  value) * red
e = (1  value) * green + value
f = (1  value) * blue
g = (1  value) * red
h = (1  value) * green
i = (1  value) * blue + value

When the saturation value is 0, the matrix is a grayscale matrix.

You can use the ascb.filters.ColorMatrixArrays.getSaturationArray( ) method to construct a saturation matrix array, given just the value.

sampleSprite.filters = [new ColorMatrixFilter(ColorMatrixArrays.getSaturationArray(2))];


Previous Page
Next Page
Converted from CHM to HTML with chm2web Pro 2.85 (unicode)