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




ActionScript 3. 0 Cookbook
ActionScript 3.0 Cookbook: Solutions for Flash Platform and Flex Application Developers
ISBN: 0596526954
EAN: 2147483647
Year: 2007
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net