本文介绍了获取显性或平均颜色的getPixels的ByteArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我这有code:

So, I've got this code:

import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Rectangle;
import flash.utils.ByteArray;

var bmd:BitmapData = new BitmapData(10, 10, true);
var seed:int = int(Math.random() * int.MAX_VALUE);
bmd.noise(seed);

var bounds:Rectangle = new Rectangle(0, 0, bmd.width, bmd.height);
var pixels:ByteArray = bmd.getPixels(bounds);

有没有一种方法来获得,高效,快速,占主导地位的颜色和/或平均颜色像素的ByteArray。

Is there a way to get, efficiently and quickly, the dominant color and/or the average color in pixels ByteArray.

噪音在这里使用的例子。我将有别的东西画在该BitmapData代替。

noise is used for the example here. I'll be having something else drawn on that BitmapData instead.

我找到了一些方法来提取的BitmapData的平均颜色口感,但这是不够的我,因为我想从一个矩形在该图像的平均水平。

I found some ways to extract the average color palate from a BitmapData, but this isn't enough for me since I want the average from a rect over that image.

在此先感谢!

推荐答案

的平均颜色很容易,只要调整的位图数据画() 荷兰国际集团是在一个1x1的位图,闪光灯会平均在复制过程中的颜色。

The average color is easy, just resize the bitmapData by draw()ing it in to a 1x1 bitmap, flash will average the color in the copy process.

var m: Matrix = new Matrix();
m.scale( 1 / bmd.width, 1 / bmd.height);
var averageColorBmd:BitmapData = new BitmapData(1, 1);
averageColorBmd.draw(bmd, m);
var averageColor:uint = averageColorBmd.getPixel(0,0);

这样的东西!

Something like that!

这篇关于获取显性或平均颜色的getPixels的ByteArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 05:42