Using as to adjust the picture's hue, brightness, grayscale, saturation, contrast, inverse, although it is not difficult, but because it involves the application of Colormatrixfilter color matrix, the use of a little trouble, so write this class colorproperty.
This class extends to the MovieClip class, adding these attributes to the MovieClip:
Hue: _color
Brightness: _brightness
Grayscale: _grayscale
Saturation degree: _saturation
Contrast degree: _contrast
Reverse phase: _invert
Of course, you can also rewrite this class to make it a new class instead of extending the MovieClip class.
Usage (same as _width,_height usage):
Import Colorproperty;
Colorproperty.init ();
Tones, with a 16-in-0xff0000
img._color=0x333399;
Trace (Img._color);
Brightness, value range: -255~255
img._brightness = 100;
Trace (img._brightness)
Grayscale, Boolean, true to grayscale, false to vice versa.
Img._grayscale = true;
Trace (Img._grayscale);
Saturation, the general range is: 0~3 suitable
Img._saturation = 3;
Trace (img._saturation);
Contrast, the range of values: 0~1
Img._contrast = 0.15;
Inverse, Boolean, true to reverse, false to Vice.
Trace (Img._contrast);
Img._invert=true;
The code is as follows:
Copy Code code as follows:
/**
* @Name: Colorproperty (movieclip color properties)
* Hue: _color, Brightness: _brightness, grayscale: _grayscale, saturation: _saturation, Contrast: _contrast, Reverse: _invert
* @author: Flashlizi
* @version: 1.0
*/
Import Flash.filters.ColorMatrixFilter;
Class Colorproperty
{
_matrix is the default identity matrix for the Colormatrixfilter class
_nred,_ngreen,_nblue is a constant of computer graphics color brightness
private static var _matrix:array = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0];
private static var _nred:number = 0.3086;
private static var _ngreen:number = 0.6094;
private static var _nblue:number = 0.0820;
function Colorproperty ()
{
}
public static function init ()
{
Setcolorproperty ();
Color color
MovieClip.prototype.addProperty ("_color", MovieClip.prototype.getColor, MovieClip.prototype.setColor);
Brightness Brightness (Value range: -255~255)
MovieClip.prototype.addProperty ("_brightness", MovieClip.prototype.getBrightness, MovieClip.prototype.setBrightness);
Grayscale Grayscale
MovieClip.prototype.addProperty ("_grayscale", MovieClip.prototype.getGrayscale, MovieClip.prototype.setGrayscale );
Saturation saturation (general range of saturation level: 0~3)
MovieClip.prototype.addProperty ("_saturation", MovieClip.prototype.getSaturation, MovieClip.prototype.setSaturation);
Contrast contrast (range of values: 0~1)
MovieClip.prototype.addProperty ("_contrast", MovieClip.prototype.getContrast, MovieClip.prototype.setContrast);
Reversed-Phase Invert
MovieClip.prototype.addProperty ("_invert", MovieClip.prototype.getInvert, MovieClip.prototype.setInvert);
}
private static function Setcolorproperty ()
{
Hue Color,getter&setter
MovieClip.prototype.getColor = function (): number
{
return movieclip.prototype._color;
}
MovieClip.prototype.setColor = function (ncolor:number): Void
{
var colorstr:string = ncolor.tostring (16);
var nred:number = number ("0x" + colorstr.slice (0, 2));
var ngreen:number = number ("0x" + colorstr.slice (2, 4));
var nblue:number = number ("0x" + colorstr.slice (4, 6));
var color_matrix:array = [1, 0, 0, 0, nRed, 0, 1, 0, 0, ngreen, 0, 0, 1, 0, nblue, 0, 0, 0, 1, 0];
This.filters = [New Colormatrixfilter (Color_matrix)];
Movieclip.prototype._color = Ncolor;
}
Brightness Brightness,getter&setter
MovieClip.prototype.getBrightness = function (): number
{
return movieclip.prototype._brightness;
}
MovieClip.prototype.setBrightness = function (offset:number): Void
{
var brightness_matrix:array = [1, 0, 0, 0, offset, 0, 1, 0, 0, offset, 0, 0, 1, 0, offset, 0, 0, 0, 1, 0];
This.filters = [New Colormatrixfilter (Brightness_matrix)];
Movieclip.prototype._brightness = offset;
}
Grayscale Grayscale,getter&setter
MovieClip.prototype.getGrayscale = function (): Boolean
{
return movieclip.prototype._grayscale;
}
MovieClip.prototype.setGrayscale = function (Yes:boolean): Void
{
if (yes)
{
var grayscale_matrix:array = [_nred, _ngreen, _nblue, 0, 0, _nred, _ngreen, _nblue, 0, 0, _nred, _ngreen, _nblue, 0, 0, 0, 0, 0, 1, 0];
This.filters = [New Colormatrixfilter (Grayscale_matrix)];
Movieclip.prototype._grayscale = true;
} else
{
Movieclip.prototype._grayscale = false;
}
}
Saturation degree Saturation,getter&setter
MovieClip.prototype.getSaturation = function (): number
{
return movieclip.prototype._saturation;
}
MovieClip.prototype.setSaturation = function (nlevel:number): Void
{
var srcra:number = (1-nlevel) * _nred + nlevel;
var srcga:number = (1-nlevel) * _ngreen;
var srcba:number = (1-nlevel) * _nblue;
var srcrb:number = (1-nlevel) * _nred;
var srcgb:number = (1-nlevel) * _ngreen + nlevel;
var srcbb:number = (1-nlevel) * _nblue;
var srcrc:number = (1-nlevel) * _nred;
var srcgc:number = (1-nlevel) * _ngreen;
var srcbc:number = (1-nlevel) * _nblue + nlevel;
var saturation_matrix:array = [Srcra, SRCGA, SRCBA, 0, 0, SRCRB, SRCGB, SRCBB, 0, 0, SRCRC, SRCGC, SRCBC, 0, 0, 0, 0, 0, 1, 0];
This.filters = [New Colormatrixfilter (Saturation_matrix)];
Movieclip.prototype._saturation = Nlevel;
}
Contrast degree Contrast,getter&setter
MovieClip.prototype.getContrast = function (): number
{
return movieclip.prototype._contrast;
}
MovieClip.prototype.setContrast = function (nlevel:number): Void
{
var scale:number = nlevel * 11;
var offset:number = 63.5-(nlevel * 698.5);
var contrast_matrix:array = [Scale, 0, 0, 0, Offset, 0, Scale, 0, 0, Offset, 0, 0, Scale, 0, offset, 0, 0, 0, 1, 0];
This.filters = [New Colormatrixfilter (Contrast_matrix)];
Movieclip.prototype._contrast = Nlevel;
}
Reversed-Phase Invert,getter&setter
MovieClip.prototype.getInvert = function (): Boolean
{
return movieclip.prototype._invert;
}
MovieClip.prototype.setInvert = function (Yes:boolean): Void
{
if (yes)
{
var Invert_matrix:array = [-1, 0, 0, 0, 255, 0,-1, 0, 0, 255, 0, 0,-1, 0, 255, 0, 0, 0, 1, 0];
This.filters = [New Colormatrixfilter (Invert_matrix)];
Movieclip.prototype._invert = true;
} else
{
Movieclip.prototype._invert = false;
}
}
}
}
Download: Colorproperty.rar