用AS来调整图片的色调、亮度、灰度、饱和度、对比度、反相虽然不难,但因为涉及到ColorMatrixFilter的颜色矩阵的应用,使用起来有点麻烦,因此写了这个类ColorProperty。
这个类是对MovieClip类扩展,为MovieClip增加了这些属性:
色调:_color
亮度:_brightness
灰度:_grayscale
饱和度:_saturation
对比度:_contrast
反相:_invert
当然,你也可以改写这个类,使之成为一个新类,而不是扩展MovieClip类。
用法(与_width,_height用法一样):
import ColorProperty;
ColorProperty.init();
//色调,用如0xFF0000的16进制
//img._color=0x333399;
//trace(img._color);
//亮度,取值范围为:-255~255
img._brightness = 100;
//trace(img._brightness)
//灰度,布尔值,true为灰度,false则反之。
//img._grayscale = true;
//trace(img._grayscale);
//饱和度,一般范围为:0~3为宜
//img._saturation = 3;
//trace(img._saturation);
//对比度,取值范围为:0~1
//img._contrast = 0.15;
//反相,布尔值,true为反相,false则反之。
//trace(img._contrast);
//img._invert=true;
代码如下:
[url=http://www.blueidea.com/articleimg/2007/04/4643/ColorProperty.rar]ColorProperty.rar[/url]