I am looking for an efficient way to filter a specific color from a bitmapData object in ActionScript 3. I am currently using a loop with readByte32 (). It takes about a second to process, which is unacceptable. I am trying to get paletteMap () to work, but still have not been able to understand its API (some really useful links? Google didn't help me ...).
Here is my current logic that I want to improve:
var n:int = bitmapData.width; for (var i:int = 0; i < n; i++) { var m:int = bitmapData.height; for (var j:int = 0; j < m; j++) { var color:int = bitmapData.getPixel(i, j); if (color == 0xCACACA) { bitmapData.setPixel32(i, j, 0x00000000); } } }
I can get a little better performance from using vectors, but it's only a little better ...
var v:Vector.<uint> = bitmapData.getVector(bitmapData.rect); var n:int = bitmapData.width * bitmapData.height; for (var i:int = 0; i < n; i++) { var color:uint = v[i]; v[i] = color == 0xFFCACACA ? 0x00000000 : color; } bitmapData.setVector(bitmapData.rect, v);
I really think that there should be a better way to do this, which only takes a few milliseconds. If someone can unlock the secrets of bitmapData for me, you will become the new leader of my people.
PS I use bitmapData.lock () and unlock (); I just did not publish the contents of the template.
source share