Previous Page
Next Page

Recipe 10.14. Changing Contrast

Problem

You want to adjust the contrast of a display object.

Solution

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

Discussion

As mentioned in Recipe 10.13, you can adjust the brightness by either scaling or offsetting color values. You can change contrast by both scaling and offsetting color values at the same time. The following matrix describes a generic contrast matrix:

a  0  0  0  b
0  a  0  0  b
0  0  a  0  b
0  0  0  1  0

You can calculate the scale and offset values from one contrast value by using the following equations:

a = value * 11
b = 63.5  (value * 698.5)

You can use the ascb.filters.ColorMatrixArrays.getContrastArray( ) method to construct a contrast array given the contrast value. The effective range for the contrast value is from 0 to 1:

sampleSprite.filters = [new ColorMatrixFilter(ColorMatrixArrays.getContrastArray(1))];

See Also

Recipe 10.13


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