AS3 - 查找的BitmapData最丰富的像素颜色 [英] AS3 - Find the most abundant pixel colour in BitmapData
问题描述
基本上,我想出现在的BitmapData code>最常见的ARGB值。也就是说,我想知道的确切的像素色彩是最丰富的形象。我试图去通过图像的每个像素,并计算时已存在的颜色出现,但是这太慢,即使是较小的图像。是否有人知道这是一个更快的方法,也许使用
BitmapData.histogram()
功能什么的?
Basically, I want to get the most common ARGB value that appears in a BitmapData
. That is, I want to know which exact pixel colour is the most abundant in the image. I tried going through every pixel of the image and counting whenever a colour that already exists comes up, but that's way too slow, even with relatively small images. Does anybody know a faster method for this, maybe using the BitmapData.histogram()
function or something?
在理想情况下这个过程应该是接近瞬时周边至少1000×1000像素的图像。
Ideally the process should be near instantaneous for images around at least 1000x1000 pixels.
推荐答案
到 bitmapData.getVector()
运行一个字典来保存号码,然后那种字典的键盘值对价值得到最大程度的关键。
Run through bitmapData.getVector()
with a Dictionary to hold numbers, then sort that Dictionary's key-value pairs by value and get the key of maximum.
var v:Vector.<uint>=yourBitmapData.getVector(yourBitmapData.rect);
var d:Dictionary=new Dictionary();
for (var i:int=v.length-1; i>=0;i--) {
if (d[v[i]]) d[v[i]]++; else d[v[i]]=1;
}
var maxkey:String=v[0].toString();
var maxval:int=0;
for (var k:String in d) {
if (d[k]>maxval) {
maxval=d[k];
maxkey=k;
}
}
return parseInt(maxkey); // or just maxkey
这篇关于AS3 - 查找的BitmapData最丰富的像素颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!