Example of getColorBoundsRect()
Here’s what the Actionscript 3 docs have to say about getColorBoundsRect()
Determines a rectangular region that either fully encloses all pixels of a specified color within the bitmap image (if the
findColorparameter is set totrue) or fully encloses all pixels that do not include the specified color (if thefindColorparameter is set tofalse).
That makes a lot more since if you see it in action. Click on the SWF below to see how the rectangle is drawn. In this case getColorBoundsRect() is returning a rectangle that encloses the selected color under the mouse pointer.
|
[ view source ] |
Here’s the meat and potatoes of the code:
private function clickHandler( e:MouseEvent ):void {
var color:uint = bmpData.getPixel32( mouseX, mouseY );
var rect:Rectangle = bmpData.getColorBoundsRect( 0xFFFFFFFF, color );
outline.graphics.clear();
outline.graphics.lineStyle( 1, 0x000000, 1 );
outline.graphics.drawRect( rect.x, rect.y, rect.width, rect.height );
}
You can read more about it on the Actionscript 3 docs. Or in the Actionscript 3 Bible, page 637.
If something here has proved valuable to you then feel free to drop a couple of bucks in the tip-jar.






