AS3得到图像的平均颜色
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AS3得到图像的平均颜色相关的知识,希望对你有一定的参考价值。
The docs for the Sekati SWC are here: http://docs.sekati.com/sekati/sekati/utils/ColorUtil.htmlAnother useful blog post: http://blog.soulwire.co.uk/code/actionscript-3/extract-average-colours-from-bitmapdata
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); } } }
以上是关于AS3得到图像的平均颜色的主要内容,如果未能解决你的问题,请参考以下文章