ActionScript 3 AS3获取图像的平均颜色
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 AS3获取图像的平均颜色相关的知识,希望对你有一定的参考价值。
package
{
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.ColorTransform;
import sekati.utils.ColorUtil;
public class Main extends Sprite
{
[Embed(source="../assets/hero.jpg")]
private var StillImage:Class;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
var image:Bitmap = new StillImage();
addChild(image);
var swatch:Sprite = new Sprite();
swatch.graphics.beginFill(0xFF0000);
swatch.graphics.drawRect(0, 0, image.width, 40);
swatch.graphics.endFill();
swatch.x = image.x;
swatch.y = image.y + image.height;
addChild(swatch);
var averageRed:int = ColorUtil.averageRed(image);
var averageGreen:int = ColorUtil.averageGreen(image);
var averageBlue:int = ColorUtil.averageBlue(image);
var colour:uint = averageRed << 16 | averageGreen << 8 | averageBlue;
trace(averageRed + ", " + averageGreen + ", " + averageBlue);
var ct:ColorTransform = new ColorTransform();
ct.color = (colour);
swatch.transform.colorTransform = ct;
var hexColour:String = "#" + colour.toString(16).toUpperCase();
trace("hexColour: "+hexColour);
}
}
}
以上是关于ActionScript 3 AS3获取图像的平均颜色的主要内容,如果未能解决你的问题,请参考以下文章
ActionScript 3 AS3:图像加载
ActionScript 3 as3全背景图像类
ActionScript 3 AS3 - 来自URL的缓存图像
ActionScript 3 来自AS3的PHP图像上传器
ActionScript 3 AS3:在图像上放置叠加层
ActionScript 3 AS3图像映射,圆形,斜角滤波器