麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 辦公 > Flash > 正文

AS類:顏色屬性ColorProperty

2024-09-12 17:50:49
字體:
來源:轉載
供稿:網友
用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;

代碼如下:

復制代碼 代碼如下:

/** 
* @Name:ColorProperty(MovieClip顏色屬性) 
* 色調:_color,亮度:_brightness,灰度:_grayscale,飽和度:_saturation,對比度:_contrast,反相:_invert 
* @author:Flashlizi 
* @version:1.0 
*/ 
import flash.filters.ColorMatrixFilter; 
class ColorProperty 

    //_matrix是ColorMatrixFilter類的默認恒等矩陣 
    //_nRed,_nGreen,_nBlue是計算機圖形顏色亮度的常量 
    //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 
        MovieClip.prototype.addProperty ("_color", MovieClip.prototype.getColor, MovieClip.prototype.setColor); 
        //亮度Brightness(取值范圍為:-255~255) 
        MovieClip.prototype.addProperty ("_brightness", MovieClip.prototype.getBrightness, MovieClip.prototype.setBrightness); 
        //灰度Grayscale 
        MovieClip.prototype.addProperty ("_grayscale", MovieClip.prototype.getGrayscale, MovieClip.prototype.setGrayscale); 
        //飽和度Saturation(飽和度級別一般范圍為:0~3) 
        MovieClip.prototype.addProperty ("_saturation", MovieClip.prototype.getSaturation, MovieClip.prototype.setSaturation); 
        //對比度Contrast(取值范圍為:0~1) 
        MovieClip.prototype.addProperty ("_contrast", MovieClip.prototype.getContrast, MovieClip.prototype.setContrast); 
        //反相Invert 
        MovieClip.prototype.addProperty ("_invert", MovieClip.prototype.getInvert, MovieClip.prototype.setInvert); 
    } 
    private static function setColorProperty () 
    { 
        //色調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,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,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,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,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; 
        } 
        //反相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; 
            } 
        } 
    } 


下載:ColorProperty.rar
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 最新中文字幕在线 | 92自拍视频| 国产黄色毛片 | a一级黄色毛片 | 亚洲国产美女视频 | 日韩视频在线不卡 | 99在线热视频 | 在线免费亚洲 | 九九热精品视频在线 | 婷婷久久综合九色综合色多多蜜臀 | 久久亚洲精品国产一区 | 亚洲免费看片网站 | 伊人午夜视频 | 亚洲男人天堂 | 亚洲一区成人在线 | 国产成人高清成人av片在线看 | 久久一级 | 一本色道久久综合狠狠躁篇适合什么人看 | 国产精品久久久久久久久久久天堂 | 国产影院一区 | 亚洲一级簧片 | 欧美成人一二三区 | 国产午夜免费不卡精品理论片 | 国产一区二区免费看 | 欧美wwwwww| 日本欧美一区二区三区在线观看 | 91精品国产99久久久久久 | wankz100%videos | 久久影城| 黄色高清免费 | 国产免费高清在线 | 黄污网址 | 精品国产一区二区三区成人影院 | 久久久精品视频国产 | 欧美精品1区 | 一本一道久久久a久久久精品91 | 国产精品高潮视频 | 91网页 | 九九热视频免费观看 | 性欧美性欧美 | 日日天日日夜日日摸 |