您的位置: 首页 > 资源下载 > 经典产品 > AS类:颜色属性ColorProperty
定时重启或关机的小工具 回到列表 雅致Flash打包工具1.0
用户名:
密 码: 忘记密码
注册会员 游览论坛 论坛帮助
 AS类:颜色属性ColorProperty

作者:flashlizi 时间: 2007-04-16 文档类型:原创 来自:蓝色理想
浏览统计 total:1262 | year:1262 | Quarter:1262 | Month:1262 | Week:469 | today:1

用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

经典论坛讨论
http://bbs.blueidea.com/thread-2736872-1-1.html

本文链接:http://www.blueidea.com/download/product/2007/4643.asp 

出处:蓝色理想
责任编辑:moby

相关文章 更多相关链接
自然选择:自然界的颜色与界面设计
Flash中的颜色矩阵
利用CSS创造多彩文字
语义化你的HTML标签和属性
标签for属性与对应的id之关系
热门搜索:CSS Fireworks 设计比赛 网页制作 Dreamweaver Studio8 Flash
站点最新 站点最新列表
方正推出徐静蕾字体
深入了解setInterval方法
一个人的鼓浪屿:花时间
百度空间首页设计大赛
淘宝首页变胖了?
Membership角色与权限管理
SEO和UCD的关系
CrossOver 参展作品选
那时,绿意盎然
5种Web图像格式简述
栏目最新 栏目最新列表
定时重启或关机的小工具
AS类:颜色属性ColorProperty
雅致Flash打包工具1.0
[Perl]文字/代码批量替换工具
一个比较漂亮的日历
用Flash制作的站长工具箱
激发你的灵感:50个优秀的Favicons
Vcastr 2.0 flv 网络播放器
Bcastr3.0 flash通用图片播放器
Cver:在线后台下载的阅读引擎

蓝色理想版权申明:除部分特别声明不要转载,或者授权我站独家播发的文章外,大家可以自由转载我站点的原创文章,但原作者和来自我站的链接必须保留(非我站原创的,按照原来自一节,自行链接)。文章版权归我站和作者共有。

转载要求:转载之图片、文件,链接请不要盗链到本站,且不准打上各自站点的水印,亦不能抹去我站点水印。

特别注意:本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

本文暂时没有评论和评分

您的评论
用户名:  口令:
说明:输入正确的用户名和密码才能参与评论。如果您不是本站会员,你可以注册 为本站会员。
注意:文章中的链接、内容等需要修改的错误,请用报告错误,以利文档及时修改。
不评分 1 2 3 4 5
注意:请不要在评论中含与内容无关的广告链接,违者封ID
请您注意:
·不良评论请用报告管理员,以利管理员及时删除。
·尊重网上道德,遵守中华人民共和国的各项有关法律法规
·承担一切因您的行为而直接或间接导致的民事或刑事法律责任
·本站评论管理人员有权保留或删除其管辖评论中的任意内容
·您在本站发表的作品,本站有权在网站内转载或引用
·参与本评论即表明您已经阅读并接受上述条款
推荐文档 | 打印文档 | 评论文档 | 报告错误  
专业书推荐 更多内容
Don't Make Me Think 第2版
HTM与CSS入门经典(第7版)
《FLASH MX2004网站开发精粹》
《CSS入门经典》
《网页配色密码》
《设计师谈网页设计思维》
《Photoshop实用技能案例详解》