Suppose I’ve converted a vector image file (.AI/.SVG) to .SWF for ease of importing dynamically as the source of an Image in Flex.
To count colors now, I have to create a “new BitMap”, then “.draw()” and iterate over all pixels and use “.getPixel()” to retrieve the color.
Unfortunately, because of anti-aliasing, this seems to return several more colors than what are actually used to draw the image (say, a black logo).
Is there a better alternative to doing this in Flex?
I’ve got a solution, but it might not be the best one.
Basically I’m just looping through the swf’s bytes using as3swf and looking for shape definitions then getting to the fills. From there I push the colors(solid fills and colors found in gradients) into an array. Since there might be duplicates, I remove them at the end.
Here’s the code:
HTH