Flash's smoothing may introduce irregularities, I guess. But given that the original poster only wanted to know grey or white, surely it's a good enough approximation for that purpose?
Ian On Sun, Mar 29, 2009 at 9:08 PM, Juan Pablo Califano <califa010.flashcod...@gmail.com> wrote: > It's indeed much faster (five times faster than transforming to grey scale), > though the results I'm getting are incorrect (the other 2 methods seems to > return consistently similar results, though trasnforming to HLS takes about > 3200 ms for a 1152 x 864 image, and transform to grey scale takes around 130 > ms). > > It could be the case that I'm doing it the wrong way, of course... This is > the code I'm using. > > > function getAverageFromScaledBitmap(src:DisplayObject):Number { > var dest:BitmapData = new BitmapData(1,1); > var mat:Matrix = new Matrix(); > var sx:Number = 1 / src.width; > var sy:Number = 1 / src.height; > > mat.scale(sx,sy); > dest.draw(src,mat,null,null,null,true); > var hls:Object = ColorUtils.RGBtoHLS(dest.getPixel(0,0)); > > return hls.l; > } > Cheers > Juan Pablo Califano > > 2009/3/29 Ian Thomas <i...@eirias.net> > >> On Sun, Mar 29, 2009 at 8:14 PM, Juan Pablo Califano >> <califa010.flashcod...@gmail.com> wrote: >> > As it's been said already, you could try converting to HLS and the get >> the >> > average luminance (brigthness). Here's a handy class to convert from RGB >> to >> > HSL and viceversa. >> > >> > http://www.dreaminginflash.com/2007/11/19/hls-to-rgb-rgb-to-hls/ >> > Another approach, which might be faster (but you'd have to test it to see >> if >> > that's true), could be transforming to bitmap to a grey scale. You would >> > then know how black / white each pixel is, so you could get the average >> > value by adding the value of each pixel and dividing for the total number >> of >> > pixels. Instead of reading the whole pixel value, you can just read one >> > channel, because since it' s a grey scale, the three color channels will >> be >> > equal. >> >> If you're going to test any kind of average pixel value, it'd be far >> faster to take a bitmap copy of the frame scaled to 1 pixel x 1 pixel >> (with smoothing on) - and just read the colour value of that pixel... >> >> HTH, >> Ian >> _______________________________________________ >> Flashcoders mailing list >> Flashcoders@chattyfig.figleaf.com >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >> > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders