您的位置: 首页 > 资源下载 > 经典产品 > AS类:颜色属性ColorProperty
定时重启或关机的小工具 回到列表 雅致Flash打包工具1.0
 AS类:颜色属性ColorProperty

作者:flashlizi 时间: 2007-04-16 文档类型:原创 来自:蓝色理想

用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 设计比赛 网页制作 web标准 用户体验 UE photoshop Dreamweaver Studio8 Flash 手绘 CG
站点最新 站点最新列表
周大福“敬•自然”设计大赛开启
国际体验设计大会7月将在京举行
中国国防科技信息中心标志征集
云计算如何让安全问题可控
云计算是多数企业唯一拥抱互联网的机会
阿里行云
云手机年终巨献,送礼标配299起
阿里巴巴CTO王坚的"云和互联网观"
1499元买真八核 云OS双蛋大促
首届COCO桌面手机主题设计大赛
栏目最新 栏目最新列表
扣代码工具——捕获者2.0
扣代码工具——捕获者
CSS 3.0 参考手册(中文版)
WebRebuild第三届年会资料
复杂背景抠毛羽三则(电子书)
第三届D2资料分享
搜索引擎优化基础知识PPT
WAP2.0知识分享PPT
文字点阵化的应用
开源ASP博客程序Cmder V2.0

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

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

特别注意:本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有,文章若有侵犯作者版权,请与我们联系,我们将立即删除修改。

您的评论
用户名:  口令:
说明:输入正确的用户名和密码才能参与评论。如果您不是本站会员,你可以注册 为本站会员。
注意:文章中的链接、内容等需要修改的错误,请用报告错误,以利文档及时修改。
不评分 1 2 3 4 5
注意:请不要在评论中含与内容无关的广告链接,违者封ID
请您注意:
·不良评论请用报告管理员,以利管理员及时删除。
·尊重网上道德,遵守中华人民共和国的各项有关法律法规
·承担一切因您的行为而直接或间接导致的民事或刑事法律责任
·本站评论管理人员有权保留或删除其管辖评论中的任意内容
·您在本站发表的作品,本站有权在网站内转载或引用
·参与本评论即表明您已经阅读并接受上述条款
推荐文档 | 打印文档 | 评论文档 | 报告错误  
专业书推荐 更多内容
网站可用性测试及优化指南
《写给大家看的色彩书1》
《跟我去香港》
众妙之门—网站UI 设计之道
《Flex 4.0 RIA开发宝典》
《赢在设计》
犀利开发—jQuery内核详解与实践
作品集 更多内容

杂⑦杂⑧ Gold NORMANA V2