getColorBoundsRect (BitmapData.getColorBoundsRect method)

public getColorBoundsRect(mask:Number, color:Number, [findColor:Boolean]) : Rectangle

Determines a rectangular region that fully encloses all pixels of a specified color within the bitmap image.

For example, if you have a source image and you want to determine the rectangle of the image that contains a nonzero alpha channel, you pass {mask: 0xFF000000, color: 0x00000000} as parameters. The entire image is searched for the bounds of pixels whose (value & mask) != color. To determine white space around an image, you pass {mask: 0xFFFFFFFF, color: 0xFFFFFFFF} to find the bounds of nonwhite pixels.

Availability: ActionScript 1.0; Flash Player 8

Parameters

mask:Number - A hexadecimal color value.

color:Number - A hexadecimal color value.

findColor:Boolean [optional] - If the value is set to true, returns the bounds of a color value in an image. If the value is set to false, returns the bounds of where this color doesn't exist in an image. The default value is true.

Returns

Rectangle - The region of the image that is the specified color.

Example

The following example shows how to determine a rectangular region that fully encloses all pixels of a specified color within the bitmap image:

import flash.display.BitmapData;
import flash.geom.Rectangle;

var myBitmapData:BitmapData = new BitmapData(100, 80, false, 0x00CCCCCC);

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc.attachBitmap(myBitmapData, this.getNextHighestDepth());
myBitmapData.fillRect(new Rectangle(0, 0, 50, 40), 0x00FF0000);

mc.onPress = function() {
    var colorBoundsRect:Rectangle = myBitmapData.getColorBoundsRect(0x00FFFFFF, 0x00FF0000, true);
    trace(colorBoundsRect); // (x=0, y=0, w=50, h=40)
}

Flash CS3


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00001406.html