Packageflash.display
Classpublic class BitmapData
InheritanceBitmapData Inheritance Object

Player version: Flash Player 8

The BitmapData class lets you create arbitrarily sized transparent or opaque bitmap images and manipulate them in various ways at runtime.

This class lets you separate bitmap rendering operations from the Flash Player internal display updating routines. By manipulating a BitmapData object directly, you can create very complex images without incurring the per frame overhead of constantly redrawing the content from vector data.

The methods of the BitmapData class support a variety of effects that are not available through the generic filter interface.

A BitmapData object contains an array of pixel data. This data can represent either a fully opaque bitmap or a transparent bitmap that contains alpha channel data. Either type of BitmapData object is stored as a buffer of 32-bit integers. Each 32-bit integer determines the properties of a single pixel in the bitmap.

Each 32-bit integer is a combination of four 8-bit channel values (from 0 to 255) that describe the alpha transparency and the red, green, and blue (ARGB) values of the pixel.

The four channels (red, green, blue, and alpha) are represented as numbers when you use them with the BitmapData.copyChannel() method or the DisplacementMapFilter.componentX and DisplacementMapFilter.componentY properties, as follows:

You can attach BitmapData objects to a MovieClip object by using the MovieClip.attachBitmap() method.

You can use a BitmapData object to fill an area in a movie clip by using the MovieClip.beginBitmapFill() method.

The maximum width and maximum height of a BitmapData object is 2880 pixels.

Calls to any method or property of a BitmapData object fail if the BitmapData object is invalid (for example, if it has height == 0 and width == 0), and upon failing those properties and methods that return Number values return -1.

See also

MovieClip.attachBitmap()
MovieClip.beginBitmapFill()


Public Properties
 Property
  height : Number
[read-only]The height of the bitmap image in pixels.
  rectangle : Rectangle
[read-only]The rectangle that defines the size and location of the bitmap image.
  transparent : Boolean
[read-only]Defines whether the bitmap image supports per-pixel transparency.
  width : Number
[read-only]The width of the bitmap image in pixels.
 Properties inherited from class Object
 __proto__, __resolve, constructor, prototype
Public Methods
 Method
  
BitmapData(width:Number, height:Number, [transparent:Boolean], [fillColor:Number])
Creates a BitmapData object with a specified width and height.
  
applyFilter(sourceBitmap:BitmapData, sourceRect:Rectangle, destPoint:Point, filter:BitmapFilter):Number
Takes a source image and a filter object and generates the filtered image.
  
Returns a new BitmapData object that is a clone of the original instance with an exact copy of the contained bitmap.
  
colorTransform(rect:Rectangle, colorTransform:ColorTransform):Void
Adjusts the color values in a specified area of a bitmap image by using a ColorTransform object.
  
compare(otherBitmapData:BitmapData):Object
Compares two BitmapData objects.
  
copyChannel(sourceBitmap:BitmapData, sourceRect:Rectangle, destPoint:Point, sourceChannel:Number, destChannel:Number):Void
Transfers data from one channel of another BitmapData object or the current BitmapData object into a channel of the current BitmapData object.
  
copyPixels(sourceBitmap:BitmapData, sourceRect:Rectangle, destPoint:Point, [alphaBitmap:BitmapData], [alphaPoint:Point], [mergeAlpha:Boolean]):Void
Provides a fast routine to perform pixel manipulation between images with no stretching, rotation, or color effects.
  
dispose():Void
Frees memory that is used to store the BitmapData object.
  
draw(source:Object, [matrix:Matrix], [colorTransform:ColorTransform], [blendMode:Object], [clipRect:Rectangle], [smooth:Boolean]):Void
Draws a source image or movie clip onto a destination image, using the Flash Player vector renderer.
  
fillRect(rect:Rectangle, color:Number):Void
Fills a rectangular area of pixels with a specified ARGB color.
  
floodFill(x:Number, y:Number, color:Number):Void
Performs a flood fill operation on an image starting at an (x, y) coordinate and filling with a certain color.
  
Determines the destination rectangle that the applyFilter() method call affects, given a BitmapData object, a source rectangle, and a filter object.
  
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.
  
Returns an integer that represents an RGB pixel value from a BitmapData object at a specific point (x, y).
  
Returns an ARGB color value that contains alpha channel data and RGB data.
  
hitTest(firstPoint:Point, firstAlphaThreshold:Number, secondObject:Object, [secondBitmapPoint:Point], [secondAlphaThreshold:Number]):Boolean
Performs pixel-level hit detection between one bitmap image and a point, rectangle or other bitmap image.
  
[static]Returns a new BitmapData object that contains a bitmap image representation of the symbol that is identified by a specified linkage ID in the library.
  
merge(sourceBitmap:BitmapData, sourceRect:Rectangle, destPoint:Point, redMult:Number, greenMult:Number, blueMult:Number, alphaMult:Number):Void
Performs per-channel blending from a source image to a destination image.
  
noise(randomSeed:Number, [low:Number], [high:Number], [channelOptions:Number], [grayScale:Boolean]):Void
Fills an image with pixels representing random noise.
  
paletteMap(sourceBitmap:BitmapData, sourceRect:Rectangle, destPoint:Point, [redArray:Array], [greenArray:Array], [blueArray:Array], [alphaArray:Array]):Void
Remaps the color channel values in an image that has up to four arrays of color palette data, one for each channel.
  
perlinNoise(baseX:Number, baseY:Number, numOctaves:Number, randomSeed:Number, stitch:Boolean, fractalNoise:Boolean, [channelOptions:Number], [grayScale:Boolean], [offsets:Object]):Void
Generates a Perlin noise image.
  
pixelDissolve(sourceBitmap:BitmapData, sourceRect:Rectangle, destPoint:Point, [randomSeed:Number], [numberOfPixels:Number], [fillColor:Number]):Number
Performs a pixel dissolve either from a source image to a destination image or by using the same image.
  
scroll(x:Number, y:Number):Void
Scrolls an image by a certain (x, y) pixel amount.
  
setPixel(x:Number, y:Number, color:Number):Void
Sets the color of a single pixel of a BitmapData object.
  
setPixel32(x:Number, y:Number, color:Number):Void
Sets the color and alpha transparency values of a single pixel of a BitmapData object.
  
threshold(sourceBitmap:BitmapData, sourceRect:Rectangle, destPoint:Point, operation:String, threshold:Number, [color:Number], [mask:Number], [copySource:Boolean]):Number
Tests pixel values in an image against a specified threshold and sets pixels that pass the test to new color values.
 Methods inherited from class Object
 addProperty, hasOwnProperty, isPropertyEnumerable, isPrototypeOf, registerClass, toString, unwatch, valueOf, watch
Property detail
heightproperty
height:Number  [read-only]

Player version: Flash Player 8

The height of the bitmap image in pixels.

Implementation
    public function get height():Number

Example
The following example shows that the height property of the BitmapData instance is read-only by trying to set it and failing:
import flash.display.BitmapData;

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

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc.attachBitmap(myBitmapData, this.getNextHighestDepth());
trace(myBitmapData.height);    // 80

myBitmapData.height = 999;
trace(myBitmapData.height);    // 80

rectangleproperty 
rectangle:Rectangle  [read-only]

Player version: Flash Player 8

The rectangle that defines the size and location of the bitmap image. The top and left of the rectangle are 0; the width and height are equal to the width and height in pixels of the BitmapData object.

Implementation
    public function get rectangle():Rectangle

Example
The following example shows that the rectangle property of the Bitmap instance is read-only by trying to set it and failing:
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());
trace(myBitmapData.rectangle);    // (x=0, y=0, w=100, h=80)

myBitmapData.rectangle = new Rectangle(1, 2, 4, 8);
trace(myBitmapData.rectangle);    // (x=0, y=0, w=100, h=80)

transparentproperty 
transparent:Boolean  [read-only]

Player version: Flash Player 8

Defines whether the bitmap image supports per-pixel transparency. You can set this value only when you construct a BitmapData object by passing in true for the transparent parameter. After you create a BitmapData object, you can check whether it supports per-pixel transparency by seeing if the value of the transparent property is true.

Implementation
    public function get transparent():Boolean

Example
The following example shows that the transparent property of the Bitmap instance is read-only by trying to set it and failing:
import flash.display.BitmapData;

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

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc.attachBitmap(myBitmapData, this.getNextHighestDepth());
trace(myBitmapData.transparent);    // false

myBitmapData.transparent = true;
trace(myBitmapData.transparent);    // false

widthproperty 
width:Number  [read-only]

Player version: Flash Player 8

The width of the bitmap image in pixels.

Implementation
    public function get width():Number

Example
The following example shows that the width property of the Bitmap instance is read-only by trying to set it and failing:
import flash.display.BitmapData;

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

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc.attachBitmap(myBitmapData, this.getNextHighestDepth());
trace(myBitmapData.width);    // 100

myBitmapData.width = 999;
trace(myBitmapData.width);    // 100

Constructor detail
BitmapData()constructor
public function BitmapData(width:Number, height:Number, [transparent:Boolean], [fillColor:Number])

Player version: Flash Player 8

Creates a BitmapData object with a specified width and height. If you specify a value for the fillColor parameter, every pixel in the bitmap is set to that color.

By default, the bitmap is created as transparent, unless you pass the value false for the transparent parameter. Once you create an opaque bitmap, you cannot change it to a transparent bitmap. Every pixel in an opaque bitmap uses only 24 bits of color channel information. If you define the bitmap as transparent, every pixel uses 32 bits of color channel information, including an alpha transparency channel.

The maximum width and maximum height of a BitmapData object is 2880 pixels. If you specify a width or height value that is greater than 2880, a new instance is not created.

Parameters
width:Number — The width of the bitmap image in pixels.
 
height:Number — The height of the bitmap image in pixels.
 
transparent:Boolean [optional] — Specifies whether the bitmap image supports per-pixel transparency. The default value is true (transparent). To create a fully transparent bitmap set the value of the transparent parameter to true and the value of the fillColor parameter to 0x00000000 (or to 0).
 
fillColor:Number [optional] — A 32-bit ARGB color value that you use to fill the bitmap image area. The default value is 0xFFFFFFFF (solid white).

Example
The following example creates a new BitmapData object. The values in this example are the default values for the transparent and fillColor parameters; you could call the constructor without these parameters and get the same result.
import flash.display.BitmapData;

var width:Number = 100;
var height:Number = 80;
var transparent:Boolean = true;
var fillColor:Number = 0xFFFFFFFF;

var bitmap_1:BitmapData = new BitmapData(width, height, transparent, fillColor);

trace(bitmap_1.width);            // 100
trace(bitmap_1.height);            // 80
trace(bitmap_1.transparent);    // true

var bitmap_2:BitmapData = new BitmapData(width, height);

trace(bitmap_2.width);            // 100
trace(bitmap_2.height);            // 80
trace(bitmap_2.transparent);    // true

Method detail
applyFilter()method
public function applyFilter(sourceBitmap:BitmapData, sourceRect:Rectangle, destPoint:Point, filter:BitmapFilter):Number

Player version: Flash Player 8

Takes a source image and a filter object and generates the filtered image.

This method relies on the behavior of built-in filter objects, which have code to determine the destination rectangle that is affected by an input source rectangle.

After a filter is applied, the resulting image can be larger than the input image. For example, if you use a BlurFilter class to blur a source rectangle of (50,50,100,100) and a destination point of (10,10), the area that changes in the destination image is larger than (10,10,60,60) because of the blurring. This happens internally during the applyFilter() call.

If the sourceRect parameter of the sourceBitmapData parameter is an interior region, such as (50,50,100,100) in a 200 x 200 image, the filter uses the source pixels outside the sourceRect parameter to generate the destination rectangle.

Parameters
sourceBitmap:BitmapData — The input bitmap image to use. The source image can be a different BitmapData object or it can refer to the current BitmapData instance.
 
sourceRect:Rectangle — A rectangle that defines the area of the source image to use as input.
 
destPoint:Point — The point within the destination image (the current BitmapData instance) that corresponds to the upper-left corner of the source rectangle.
 
filter:BitmapFilter — The filter object that you use to perform the filtering operation. Each type of filter has certain requirements, as follows:
  • BlurFilter — This filter can use source and destination images that are either opaque or transparent. If the formats of the images do not match, the copy of the source image that is made during the filtering matches the format of the destination image.
  • BevelFilter, DropShadowFilter, GlowFilter — The destination image of these filters must be a transparent image. Calling DropShadowFilter or GlowFilter creates an image that contains the alpha channel data of the drop shadow or glow. It does not create the drop shadow onto the destination image. If you use any of these filters with an opaque destination image, an error code value of -6 is returned.
  • ConvolutionFilter — This filter can use source and destination images that are either opaque or transparent.
  • ColorMatrixFilter — This filter can use source and destination images that are either opaque or transparent.
  • DisplacementMapFilter — This filter can use source and destination images that are either opaque or transparent, but the source and destination image formats must be the same.

Returns
Number — A number that indicates whether the filter was applied successfully. If 0 is returned, the filter was applied successfully. If a negative number is returned, an error occurred during the application of the filter.

See also


Example
The following example shows how to apply a bevel filter to a BitmapData instance:
import flash.display.BitmapData;
import flash.filters.BevelFilter;
import flash.geom.Point;

var myBitmapData:BitmapData = new BitmapData(100, 80, true, 0xCCCCCCCC);

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc.attachBitmap(myBitmapData, this.getNextHighestDepth());

var filter:BevelFilter = new BevelFilter(5, 45, 0xFFFF00, 0.8, 0x0000FF, 0.8, 20, 20, 1, 3, "inner", false);

mc.onPress = function() {
    myBitmapData.applyFilter(myBitmapData, myBitmapData.rectangle, new Point(0, 0), filter);
}

clone()method 
public function clone():BitmapData

Player version: Flash Player 8

Returns a new BitmapData object that is a clone of the original instance with an exact copy of the contained bitmap.

Returns
BitmapData — A new BitmapData object that is identical to the original.

Example
The following example creates three BitmapData objects and compares them. You can create the bitmap_1 instance by using the BitmapData constructor. You create the bitmap_2 instance by setting it equal to bitmap_1. You create he clonedBitmap instance by cloning bitmap_1. Notice that although bitmap_2 evaluates as being equal to bitmap_1, clonedBitmap does not, even though it contains the same values as bitmap_1.
import flash.display.BitmapData;

var bitmap_1:BitmapData = new BitmapData(100, 80, false, 0x000000);
var bitmap_2:BitmapData = bitmap_1;
var clonedBitmap:BitmapData = bitmap_1.clone();

trace(bitmap_1 == bitmap_2);        // true
trace(bitmap_1 == clonedBitmap);    // false

for(var i in bitmap_1) {
    trace(">> " + i + ": " + bitmap_1[i]);
    // >> generateFilterRect: [type Function]
    // >> dispose: [type Function]
    // >> clone: [type Function]
    // >> copyChannel: [type Function]
    // >> noise: [type Function]
    // >> merge: [type Function]
    // >> paletteMap: [type Function]
    // >> hitTest: [type Function]
    // >> colorTransform: [type Function]
    // >> perlinNoise: [type Function]
    // >> getColorBoundsRect: [type Function]
    // >> floodFill: [type Function]
    // >> setPixel32: [type Function]
    // >> getPixel32: [type Function]
    // >> pixelDissolve: [type Function]
    // >> draw: [type Function]
    // >> threshold: [type Function]
    // >> scroll: [type Function]
    // >> applyFilter: [type Function]
    // >> copyPixels: [type Function]
    // >> fillRect: [type Function]
    // >> setPixel: [type Function]
    // >> getPixel: [type Function]
    // >> transparent: false
    // >> rectangle: (x=0, y=0, w=100, h=80)
    // >> height: 80
    // >> width: 100
}

for(var i in clonedBitmap) {
    trace(">> " + i + ": " + clonedBitmap[i]);
    // >> generateFilterRect: [type Function]
    // >> dispose: [type Function]
    // >> clone: [type Function]
    // >> copyChannel: [type Function]
    // >> noise: [type Function]
    // >> merge: [type Function]
    // >> paletteMap: [type Function]
    // >> hitTest: [type Function]
    // >> colorTransform: [type Function]
    // >> perlinNoise: [type Function]
    // >> getColorBoundsRect: [type Function]
    // >> floodFill: [type Function]
    // >> setPixel32: [type Function]
    // >> getPixel32: [type Function]
    // >> pixelDissolve: [type Function]
    // >> draw: [type Function]
    // >> threshold: [type Function]
    // >> scroll: [type Function]
    // >> applyFilter: [type Function]
    // >> copyPixels: [type Function]
    // >> fillRect: [type Function]
    // >> setPixel: [type Function]
    // >> getPixel: [type Function]
    // >> transparent: false
    // >> rectangle: (x=0, y=0, w=100, h=80)
    // >> height: 80
    // >> width: 100
}
To further demonstrate the relationships between bitmap_1, bitmap_2, and clonedBitmap the following example modifies the pixel value at (1, 1) of bitmap_1. Modifying pixel value at (1, 1) demonstrates that the clone() method creates an instance based on values of the bitmap_1 instance instead of referring to the values.
import flash.display.BitmapData;

var bitmap_1:BitmapData = new BitmapData(100, 80, false, 0x000000);
var bitmap_2:BitmapData = bitmap_1;
var clonedBitmap:BitmapData = bitmap_1.clone();

trace(bitmap_1.getPixel32(1, 1));        // -16777216
trace(bitmap_2.getPixel32(1, 1));        // -16777216
trace(clonedBitmap.getPixel32(1, 1));    // -16777216

bitmap_1.setPixel32(1, 1, 0xFFFFFF);

trace(bitmap_1.getPixel32(1, 1));        // -1
trace(bitmap_2.getPixel32(1, 1));        // -1
trace(clonedBitmap.getPixel32(1, 1));    // -16777216

colorTransform()method 
public function colorTransform(rect:Rectangle, colorTransform:ColorTransform):Void

Player version: Flash Player 8

Adjusts the color values in a specified area of a bitmap image by using a ColorTransform object. If the rectangle matches the boundaries of the bitmap image, this method transforms the color values of the entire image.

Parameters
rect:Rectangle — A Rectangle object that defines the area of the image in which the ColorTransform object is applied.
 
colorTransform:ColorTransform — A ColorTransform object that describes the color transformation values to apply.

See also


Example
The following example shows how to apply a color transform operation to a BitmapData instance.
import flash.display.BitmapData;
import flash.geom.ColorTransform;

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

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc.attachBitmap(myBitmapData, this.getNextHighestDepth());

mc.onPress = function() {
    myBitmapData.colorTransform(myBitmapData.rectangle, new ColorTransform(1, 0, 0, 1, 255, 0, 0, 0));
}

compare()method 
public function compare(otherBitmapData:BitmapData):Object

Player version: Flash Player 9

Compares two BitmapData objects. If the two BitmapData objects have the same dimensions (width and height), the method returns a new BitmapData object, in which each pixel is the "difference" between the pixels in the two source objects:

For example, consider the following two BitmapData objects:

var bmd1:BitmapData = new BitmapData(50, 50, true, 0xFFFF0000);
var bmd2:BitmapData = new BitmapData(50, 50, true, 0xCCFFAA00);
var diffBmpData:BitmapData = bmd1.compare(bmd2);

Note: The colors used to fill the two BitmapData objects have slightly different RGB values (0xFF0000 and 0xFFAA00). The result of the compare() method is a new BitmapData object with each pixel showing the difference in the RGB values between the two bitmaps.

Consider the following two BitmapData objects, in which the RGB colors are the same, but the alpha values are different:

var bmd1:BitmapData = new BitmapData(50, 50, true, 0xFFFFAA00);
var bmd2:BitmapData = new BitmapData(50, 50, true, 0xCCFFAA00);
var diffBmpData:BitmapData = bmd1.compare(bmd2);

The result of the compare() method is a new BitmapData object with each pixel showing the difference in the alpha values between the two bitmaps.

If the BitmapData objects are equivalent (with the same width, height, and identical pixel values), the method returns the number 0.

If no argument is passed or if the argument is not a BitmapData object, the method returns -1.

If either BitmapData object has been disposed of, the method returns -2.

If the widths of the BitmapData objects are not equal, but the heights are the same, the method returns the number -3.

If the heights of the BitmapData objects are not equal, but the widths are the same, the method returns the number -4.

The following example compares two Bitmap objects with different widths (50 and 60):

var bmd1:BitmapData = new BitmapData(100, 50, false, 0xFFFF0000);
var bmd2:BitmapData = new BitmapData(100, 60, false, 0xFFFFAA00);
trace(bmd1.compare(bmd2)); // -3
Parameters
otherBitmapData:BitmapData — The BitmapData object to compare with the source BitmapData object.

Returns
Object — If the two BitmapData objects have the same dimensions (width and height), the method returns a new BitmapData object that has the difference between the two objects (see the main discussion). If the BitmapData objects are equivalent, the method returns the number 0. If no argument is passed or if the argument is not a BitmapData object, the method returns -1. If either BitmapData object has been disposed of, the method returns -2. If the widths of the BitmapData objects are not equal, the method returns the number -3. If the heights of the BitmapData objects are not equal, the method returns the number -4.
copyChannel()method 
public function copyChannel(sourceBitmap:BitmapData, sourceRect:Rectangle, destPoint:Point, sourceChannel:Number, destChannel:Number):Void

Player version: Flash Player 8

Transfers data from one channel of another BitmapData object or the current BitmapData object into a channel of the current BitmapData object. All of the data in the other channels in the destination BitmapData object are preserved.

The source channel value and destination channel value can be one of the following values or the sum of any of the values:

Parameters
sourceBitmap:BitmapData — The input bitmap image to use. The source image can be a different BitmapData object or it can refer to the current BitmapData object.
 
sourceRect:Rectangle — The source Rectangle object. If you only want to copy channel data from a smaller area within the bitmap, specify a source rectangle that is smaller than the overall size of the BitmapData object.
 
destPoint:Point — The destination Point object that represents the upper-left corner of the rectangular area where the new channel data is placed. If you want to copy channel data from one area to a different area in the destination image, specify a point other than (0,0).
 
sourceChannel:Number — The source channel. Use a value from the set (1,2,4,8), which represent red, green, blue, and alpha channels, respectively, or a sum of any of the values.
 
destChannel:Number — The destination channel. Use a value from the set (1,2,4,8), which represent red, green, blue, and alpha channels, respectively, or a sum of any of the values.

See also


Example
The following example shows how to copy a source ARGB channel from a BitmapData object back onto itself at a different location:
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;

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

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc.attachBitmap(myBitmapData, this.getNextHighestDepth());

mc.onPress = function() {
    myBitmapData.copyChannel(myBitmapData, new Rectangle(0, 0, 50, 80), new Point(51, 0), 3, 1);
}

copyPixels()method 
public function copyPixels(sourceBitmap:BitmapData, sourceRect:Rectangle, destPoint:Point, [alphaBitmap:BitmapData], [alphaPoint:Point], [mergeAlpha:Boolean]):Void

Player version: Flash Player 8

Provides a fast routine to perform pixel manipulation between images with no stretching, rotation, or color effects. This method copies a rectangular area of a source image to a rectangular area of the same size at the destination point of the destination BitmapData object.

If include the alphaBitmap and alphaPoint parameters, you can use a secondary image as an alpha source for the source image. If the source image has alpha data, both sets of alpha data are used to composite pixels from the source image to the destination image. The alphaPoint parameter is the point in the alpha image that corresponds to the upper-left corner of the source rectangle. Any pixels outside the intersection of the source image and alpha image are not copied to the destination image.

The mergeAlpha property controls whether or not the alpha channel is used when a transparent image is copied onto another transparent image. To simply copy pixels (with no alpha used), set the mergeAlpha property to false. Then all pixels are copied from source to destination. By default, the mergeAlpha property is false.

Parameters
sourceBitmap:BitmapData — The input bitmap image from which to copy pixels. The source image can be a different BitmapData instance, or it can refer to the current BitmapData instance.
 
sourceRect:Rectangle — A rectangle that defines the area of the source image to use as input.
 
destPoint:Point — The destination point, that represents the upper-left corner of the rectangular area where the new pixels are placed.
 
alphaBitmap:BitmapData [optional] — A secondary, alpha BitmapData object source.
 
alphaPoint:Point [optional] — The point in the alpha BitmapData object source that corresponds to the upper-left corner of the sourceRect parameter.
 
mergeAlpha:Boolean [optional] — A Boolean value:To use the alpha channel, set the value to true. To copy pixels with no alpha channel, set the value to false.

Example
The following example shows how to copy pixels from one BitmapData instance to another.
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;

var bitmapData_1:BitmapData = new BitmapData(100, 80, false, 0x00CCCCCC);
var bitmapData_2:BitmapData = new BitmapData(100, 80, false, 0x00FF0000);

var mc_1:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc_1.attachBitmap(bitmapData_1, this.getNextHighestDepth());

var mc_2:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc_2.attachBitmap(bitmapData_2, this.getNextHighestDepth());
mc_2._x = 101;

mc_1.onPress = function() {
    bitmapData_2.copyPixels(bitmapData_1, new Rectangle(0, 0, 50, 80), new Point(51, 0));
}

mc_2.onPress = function() {
    bitmapData_1.copyPixels(bitmapData_2, new Rectangle(0, 0, 50, 80), new Point(51, 0));
}

dispose()method 
public function dispose():Void

Player version: Flash Player 8

Frees memory that is used to store the BitmapData object.

When this method is called on an image, the width and height of the image are set to 0. After a BitmapData object's memory has been freed, calls to methods and properties of the BitmapData instance fail, returning a value of -1.


Example
The following example shows how to release the memory of a BitmapData instance, which results in a cleared instance.
import flash.display.BitmapData;

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

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc.attachBitmap(myBitmapData, this.getNextHighestDepth());

mc.onPress = function() {
    myBitmapData.dispose();

    trace(myBitmapData.width);            // -1
    trace(myBitmapData.height);            // -1
    trace(myBitmapData.transparent);    // -1
}

draw()method 
public function draw(source:Object, [matrix:Matrix], [colorTransform:ColorTransform], [blendMode:Object], [clipRect:Rectangle], [smooth:Boolean]):Void

Player version: Flash Player 8

Draws a source image or movie clip onto a destination image, using the Flash Player vector renderer. You can specify a transformation matrix, a ColorTransform object, a blend mode setting, and a destination Rectangle object to control how the rendering performs. Optionally, you can specify whether the bitmap should be smoothed when scaled. This works only if the source object is a BitmapData object.

This method directly corresponds to how objects are drawn using the standard vector renderer for objects in the authoring tool interface.

A source MovieClip object does not use any of its on-stage transformations for this call. It is treated as it exists in the library or file, with no matrix transform, no color transform, and no blend mode. If you want to draw the movie clip by using its own transform properties, you can use its Transform object to pass the various transformation properties.

Parameters
source:Object — The BitmapData object to draw.
 
matrix:Matrix [optional] — A Matrix object used to scale, rotate, or translate the coordinates of the bitmap. If no object is supplied, the bitmap image will not be transformed. Set this parameter to an identity matrix, created using the default new Matrix() constructor, if you must pass this parameter but you do not want to transform the image.
 
colorTransform:ColorTransform [optional] — A ColorTransform object that you use to adjust the color values of the bitmap. If no object is supplied, the bitmap image's colors will not be transformed. Set this parameter to a ColorTransform object created using the default new ColorTransform() constructor, if you must pass this parameter but you do not want to transform the image.
 
blendMode:Object [optional] — A blend mode setting for the transformation. This parameter can be either an integer (from 1 through 14) or a string (such as "normal" or "darken"). For a list of valid blendMode values, see the blendMode property of the MovieClip class.
 
clipRect:Rectangle [optional] — A Rectangle object. If you do not supply this value, no clipping occurs.
 
smooth:Boolean [optional] — A Boolean value that determines whether a BitmapData object is smoothed when scaled or rotated, due to a scaling or rotation in the matrix parameter. The default value is false. The smoothing parameter only applies if the source parameter is a BitmapData object. With smoothing set to false, the rotated or scaled BitmapData image can appear pixelated or jagged. For example, the following two images use the same BitmapData object for the source parameter, but the smoothing parameter is set to true on the left and false on the right:

Two images: the left one with smoothing and the right one without smoothing.

Drawing a bitmap with smoothing set to true takes longer than doing so with smoothing set to false.

See also


Example
The following example shows how to draw from a source MovieClip instance to a BitmapData object.
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Matrix;
import flash.geom.ColorTransform;

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

var mc_1:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc_1.attachBitmap(myBitmapData, this.getNextHighestDepth());

var mc_2:MovieClip = createRectangle(50, 40, 0xFF0000);
mc_2._x = 101;

var myMatrix:Matrix = new Matrix();
myMatrix.rotate(Math.PI/2);

var translateMatrix:Matrix = new Matrix();
translateMatrix.translate(70, 15);

myMatrix.concat(translateMatrix);

var myColorTransform:ColorTransform = new ColorTransform(0, 0, 1, 1, 0, 0, 255, 0);
var blendMode:String = "normal";

var myRectangle:Rectangle = new Rectangle(0, 0, 100, 80);
var smooth:Boolean = true;

mc_1.onPress = function() {
    myBitmapData.draw(mc_2, myMatrix, myColorTransform, blendMode, myRectangle, smooth);
}

function createRectangle(width:Number, height:Number, color:Number):MovieClip {
    var depth:Number = this.getNextHighestDepth();
    var mc:MovieClip = this.createEmptyMovieClip("mc_" + depth, depth);
    mc.beginFill(color);
    mc.lineTo(0, height);
    mc.lineTo(width, height);
    mc.lineTo(width, 0);
    mc.lineTo(0, 0);
    return mc;
}

fillRect()method 
public function fillRect(rect:Rectangle, color:Number):Void

Player version: Flash Player 8

Fills a rectangular area of pixels with a specified ARGB color.

Parameters
rect:Rectangle — The rectangular area to fill.
 
color:Number — The ARGB color value that fills the area. ARGB colors are often specified in hexadecimal format; for example, 0xFF336699.

See also


Example
The following example shows how to fill an area that is defined by a Rectangle within a BitmapData with a color.
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());

mc.onPress = function() {
    myBitmapData.fillRect(new Rectangle(0, 0, 50, 40), 0x00FF0000);
}

floodFill()method 
public function floodFill(x:Number, y:Number, color:Number):Void

Player version: Flash Player 8

Performs a flood fill operation on an image starting at an (x, y) coordinate and filling with a certain color. The floodFill() method is similar to the paint bucket tool in various painting programs. The color is an ARGB color that contains alpha information and color information.

Parameters
x:Number — The x coordinate of the image.
 
y:Number — The y coordinate of the image.
 
color:Number — The ARGB color to use as a fill. ARGB colors are often specified in hexadecimal format, like 0xFF336699.

Example
The following example shows how to apply a flood fill a color into to an image starting at the point where a user clicks the mouse within a BitmapData object.
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() {
    myBitmapData.floodFill(_xmouse, _ymouse, 0x000000FF);
}

generateFilterRect()method 
public function generateFilterRect(sourceRect:Rectangle, filter:BitmapFilter):Rectangle

Player version: Flash Player 8

Determines the destination rectangle that the applyFilter() method call affects, given a BitmapData object, a source rectangle, and a filter object.

For example, a blur filter normally affects an area larger than the size of the original image. A 100 x 200 pixel image that is being filtered by a default BlurFilter instance, where blurX = blurY = 4 generates a destination rectangle of (-2,-2,104,204). The generateFilterRect() method lets you find out the size of this destination rectangle in advance so that you can size the destination image appropriately before performing a filter operation.

Some filters clip their destination rectangle based on the source image size. For example, an inner DropShadow does not generate a larger result than its source image. In this API, the BitmapData object is used as the source bounds and not the source rect parameter.

Parameters
sourceRect:Rectangle — A rectangle defining the area of the source image to use as input.
 
filter:BitmapFilter — A filter object that you use to calculate the destination rectangle.

Returns
Rectangle — A destination rectangle computed by using an image, the sourceRect parameter, and a filter.

Example
The following example shows how to determine the destination rectangle that the applyfilter() method affects:
import flash.display.BitmapData;
import flash.filters.BevelFilter;
import flash.geom.Rectangle;

var myBitmapData:BitmapData = new BitmapData(100, 80, true, 0xCCCCCCCC);

var filter:BevelFilter = new BevelFilter(5, 45, 0xFFFF00, 0.8, 0x0000FF, 0.8, 20, 20, 1, 3, "outter", false);

var filterRect:Rectangle = myBitmapData.generateFilterRect(myBitmapData.rectangle, filter);

trace(filterRect);    // (x=-31, y=-31, w=162, h=142)

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

Player version: Flash Player 8

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.

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)
}

getPixel()method 
public function getPixel(x:Number, y:Number):Number

Player version: Flash Player 8

Returns an integer that represents an RGB pixel value from a BitmapData object at a specific point (x, y). The getPixel() method returns an unmultiplied pixel value. No alpha information is returned.

All pixels in a BitmapData object are stored as premultiplied color values. A premultiplied image pixel has the red, green, and blue color channel values already multiplied by the alpha data. For example, if the alpha value is 0, the values for the RGB channels are also 0, independent of their unmultiplied values.

This loss of data can cause some problems when you are performing operations. All Flash Player methods take and return unmultiplied values. The internal pixel representation is unmultiplied before it is returned as a value. During a set operation, the pixel value is premultiplied before setting the raw image pixel.

Parameters
x:Number — The x position of the pixel.
 
y:Number — The y position of the pixel.

Returns
Number — A number that represents an RGB pixel value. If the (x, y) coordinates are outside the bounds of the image, 0 is returned.

See also


Example
The following example uses the getPixel() method to retrieve the RGB value of a pixel at a specific x and y position.
import flash.display.BitmapData;

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

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc.attachBitmap(myBitmapData, this.getNextHighestDepth());
trace("0x" + myBitmapData.getPixel(0, 0).toString(16));    // 0xcccccc

getPixel32()method 
public function getPixel32(x:Number, y:Number):Number

Player version: Flash Player 8

Returns an ARGB color value that contains alpha channel data and RGB data. This method is similar to the getPixel() method, which returns an RGB color without alpha channel data.

Parameters
x:Number — The x position of the pixel.
 
y:Number — The y position of the pixel.

Returns
Number — A number that represent an ARGB pixel value. If the (x, y) coordinates are outside the bounds of the image, 0 is returned. If the bitmap was created as an opaque bitmap and not a transparent one, then this method will return an error code of -1.

See also


Example
The following example uses the getPixel32() method to retrieve the ARGB value of a pixel at a specific x and y position:
import flash.display.BitmapData;

var myBitmapData:BitmapData = new BitmapData(100, 80, true, 0xFFAACCEE);

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc.attachBitmap(myBitmapData, this.getNextHighestDepth());

var alpha:String = (myBitmapData.getPixel32(0, 0) >> 24 & 0xFF).toString(16);
trace(">> alpha: " + alpha);    // ff

var red:String = (myBitmapData.getPixel32(0, 0) >> 16 & 0xFF).toString(16);
trace(">> red: " + red);        // aa

var green:String = (myBitmapData.getPixel32(0, 0) >> 8 & 0xFF).toString(16);
trace(">> green: " + green);    // cc

var blue:String = (myBitmapData.getPixel32(0, 0) & 0xFF).toString(16);
trace(">> blue: " + blue);        // ee

trace("0x" + alpha + red + green + blue);    // 0xffaaccee

hitTest()method 
public function hitTest(firstPoint:Point, firstAlphaThreshold:Number, secondObject:Object, [secondBitmapPoint:Point], [secondAlphaThreshold:Number]):Boolean

Player version: Flash Player 8

Performs pixel-level hit detection between one bitmap image and a point, rectangle or other bitmap image. No stretching, rotation, or other transformation of either object is considered when doing the hit test.

If an image is an opaque image, it is considered a fully opaque rectangle for this method. Both images must be transparent images to perform pixel-level hit testing that considers transparency. When you are testing two transparent images, the alpha threshold parameters control what alpha channel values, from 0 to 255, are considered opaque.

Parameters
firstPoint:Point — A point that defines a pixel location in the current BitmapData instance.
 
firstAlphaThreshold:Number — The highest alpha channel value that is considered opaque for this hit test.
 
secondObject:Object — A Rectangle, Point, or BitmapData object.
 
secondBitmapPoint:Point [optional] — A point that defines a pixel location in the second BitmapData object. Use this parameter only when the value of secondObject is a BitmapData object.
 
secondAlphaThreshold:Number [optional] — The highest alpha channel value that is considered opaque in the second BitmapData object. Use this parameter only when the value of secondObject is a BitmapData object and both BitmapData objects are transparent.

Returns
Boolean — A Boolean value. If there is a hit, returns a value of true; otherwise, false.

Example
The following example shows how to determine if a BitmapData object is colliding with a MovieClip.
import flash.display.BitmapData;
import flash.geom.Point;

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

var mc_1:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc_1.attachBitmap(myBitmapData, this.getNextHighestDepth());

var mc_2:MovieClip = createRectangle(20, 20, 0xFF0000);

var destPoint:Point = new Point(myBitmapData.rectangle.x, myBitmapData.rectangle.y);
var currPoint:Point = new Point();

mc_1.onEnterFrame = function() {
    currPoint.x = mc_2._x;
    currPoint.y = mc_2._y;
    if(myBitmapData.hitTest(destPoint, 255, currPoint)) {
        trace(">> Collision at x:" + currPoint.x + " and y:" + currPoint.y);
    }
}

mc_2.startDrag(true);

function createRectangle(width:Number, height:Number, color:Number):MovieClip {
    var depth:Number = this.getNextHighestDepth();
    var mc:MovieClip = this.createEmptyMovieClip("mc_" + depth, depth);
    mc.beginFill(color);
    mc.lineTo(0, height);
    mc.lineTo(width, height);
    mc.lineTo(width, 0);
    mc.lineTo(0, 0);
    return mc;
}

loadBitmap()method 
public static function loadBitmap(id:String):BitmapData

Player version: Flash Player 8

Returns a new BitmapData object that contains a bitmap image representation of the symbol that is identified by a specified linkage ID in the library.

Parameters
id:String — A linkage ID of a symbol in the library.

Returns
BitmapData — A bitmap image representation of the symbol.

Example
The following example loads a bitmap with the linkageId libraryBitmap from your library. You must attach it to a MovieClip object to give it a visual representation.
import flash.display.BitmapData;

var linkageId:String = "libraryBitmap";
var myBitmapData:BitmapData = BitmapData.loadBitmap(linkageId);
trace(myBitmapData instanceof BitmapData);    // true

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc.attachBitmap(myBitmapData, this.getNextHighestDepth());

merge()method 
public function merge(sourceBitmap:BitmapData, sourceRect:Rectangle, destPoint:Point, redMult:Number, greenMult:Number, blueMult:Number, alphaMult:Number):Void

Player version: Flash Player 8

Performs per-channel blending from a source image to a destination image. The following formula is used for each channel:

new red dest = (red source * redMult) + (red dest * (256 - redMult) / 256;

The redMult, greenMult, blueMult, and alphaMult values are the multipliers used for each color channel. Their valid range is from 0 to 256.

Parameters
sourceBitmap:BitmapData — The input bitmap image to use. The source image can be a different BitmapData object, or it can refer to the current BitmapData object.
 
sourceRect:Rectangle — A rectangle that defines the area of the source image to use as input.
 
destPoint:Point — The point within the destination image (the current BitmapData instance) that corresponds to the upper-left corner of the source rectangle.
 
redMult:Number — A number by which to multiply the red channel value.
 
greenMult:Number — A number by which to multiply the green channel value.
 
blueMult:Number — A number by which to multiply the blue channel value.
 
alphaMult:Number — A number by which to multiply the alpha transparency value.

Example
The following example shows how to merge part of one BitmapData with another.
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;

var bitmapData_1:BitmapData = new BitmapData(100, 80, false, 0x00CCCCCC);
var bitmapData_2:BitmapData = new BitmapData(100, 80, false, 0x00FF0000);

var mc_1:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc_1.attachBitmap(bitmapData_1, this.getNextHighestDepth());

var mc_2:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc_2.attachBitmap(bitmapData_2, this.getNextHighestDepth());
mc_2._x = 101;

mc_1.onPress = function() {
    bitmapData_1.merge(bitmapData_2, new Rectangle(0, 0, 50, 40), new Point(25, 20), 128, 0, 0, 0);
}

noise()method 
public function noise(randomSeed:Number, [low:Number], [high:Number], [channelOptions:Number], [grayScale:Boolean]):Void

Player version: Flash Player 8

Fills an image with pixels representing random noise.

Parameters
randomSeed:Number — The random seed to use.
 
low:Number [optional] — The lowest value to generate for each channel (0 to 255). The default is 0.
 
high:Number [optional] — The highest value to generate for each channel (0 to 255). The default is 255.
 
channelOptions:Number [optional] — A number that can be a combination of any of the four color channel values: 1 (red), 2 (green), 4 (blue), and 8(alpha). You can use the logical OR operator | to combine channel values. The default value is (1 | 2 | 4).
 
grayScale:Boolean [optional] — A Boolean value. If the value is true, a grayscale image is created by setting all of the color channels to the same value. The alpha channel selection is not affected by setting this parameter to true. The default value is false.

Example
The following example shows how to apply pixel noise to a BitmapData object for both a color and black-and-white bitmap.
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;

var bitmapData_1:BitmapData = new BitmapData(100, 80, false, 0x00CCCCCC);
var bitmapData_2:BitmapData = new BitmapData(100, 80, false, 0x00FF0000);

var mc_1:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc_1.attachBitmap(bitmapData_1, this.getNextHighestDepth());

var mc_2:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc_2.attachBitmap(bitmapData_2, this.getNextHighestDepth());
mc_2._x = 101;

mc_1.onPress = function() {
        bitmapData_1.merge(bitmapData_2, new Rectangle(0, 0, 50, 40), new Point(25, 20), 128, 0, 0, 0);
}

mc_1.onPress = function() {
        bitmapData_1.noise(128, 0, 255, 1, true);
}

mc_2.onPress = function() {
        bitmapData_2.noise(128);
}

paletteMap()method 
public function paletteMap(sourceBitmap:BitmapData, sourceRect:Rectangle, destPoint:Point, [redArray:Array], [greenArray:Array], [blueArray:Array], [alphaArray:Array]):Void

Player version: Flash Player 8

Remaps the color channel values in an image that has up to four arrays of color palette data, one for each channel.

Flash Player uses the following steps to generate the resulting image:

After the red, green, blue, and alpha values are computed, they are added together using standard 32-bit-integer arithmetic. The red, green, blue, and alpha channel values of each pixel are extracted into separate 0 to 255 values. These values are used to look up new color values in the appropriate array: redArray, greenArray, blueArray, and alphaArray. Each of these four arrays should contain 256 values. After all four of the new channel values are retrieved, they are combined into a standard ARGB value that is applied to the pixel.

Cross-channel effects can be supported with this method. Each input array can contain full 32-bit values, and there is no shifting when the values are added together. This routine does not support per-channel clamping.

If no array is specified for a channel, the color channel is simply copied from the source image to the destination image.

You can use this method for a variety of effects such as general palette mapping (taking one channel and converting it to a false color image). You can also use this method for a variety of advanced color manipulation algorithms, such as gamma, curves, levels, and quantizing.

Parameters
sourceBitmap:BitmapData — The input bitmap image to use. The source image can be a different BitmapData object, or it can refer to the current BitmapData object.
 
sourceRect:Rectangle — A rectangle that defines the area of the source image to use as input.
 
destPoint:Point — The point within the destination image (the current BitmapData object) that corresponds to upper-left corner of the source rectangle.
 
redArray:Array [optional] — If redArray is not null, red = redArray[source red value] else red = source rect value.
 
greenArray:Array [optional] — If greenArray is not null, green = greenArray[source green value] else green = source green value.
 
blueArray:Array [optional] — If blueArray is not null, blue = blueArray[source blue value] else blue = source blue value.
 
alphaArray:Array [optional] — If alphaArray is not null, alpha = alphaArray[source alpha value] else alpha = source alpha value.

Example
The following example shows how to use a palette map to convert solid red to green, and solid green to red in a single BitmapData object.
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;

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

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth()); mc.attachBitmap(myBitmapData, this.getNextHighestDepth());

myBitmapData.fillRect(new Rectangle(51, 0, 50, 80), 0x0000FF00);

mc.onPress = function() {
    var redArray:Array = new Array(256);
    var greenArray:Array = new Array(256);

    for(var i = 0; i < 255; i++) {
        redArray[i] = 0x00000000;
        greenArray[i] = 0x00000000;
    }

    redArray[0xFF] = 0x0000FF00;
    greenArray[0xFF] = 0x00FF0000;

    myBitmapData.paletteMap(myBitmapData, new Rectangle(0, 0, 100, 40), new Point(0, 0), redArray, greenArray, null, null);
}

perlinNoise()method 
public function perlinNoise(baseX:Number, baseY:Number, numOctaves:Number, randomSeed:Number, stitch:Boolean, fractalNoise:Boolean, [channelOptions:Number], [grayScale:Boolean], [offsets:Object]):Void

Player version: Flash Player 8

Generates a Perlin noise image.

The Perlin noise generation algorithm interpolates and combines individual random noise functions (called octaves) into a single function that generates more natural-seeming random noise. Like musical octaves, each octave function is twice the frequency of the one before it. Perlin noise has been described as a "fractal sum of noise" because it combines multiple sets of noise data with different levels of detail.

You can use Perlin noise functions to simulate natural phenomena and landscapes, such as wood grain, clouds, and mountain ranges. In most cases, the output of a Perlin noise function is not displayed directly but is used to enhance other images and give them pseudo-random variations.

Simple digital random noise functions often produce images with harsh, contrasting points. This kind of harsh contrast is not often found in nature. The Perlin noise algorithm blends multiple noise functions that operate at different levels of detail. This algorithm results in smaller variations among neighboring pixel values.

Note: The Perlin noise algorithm is named for Ken Perlin, who developed it after generating computer graphics for the 1982 film Tron. Perlin received an Academy Award for Technical Achievement for the Perlin Noise function in 1997.

Parameters
baseX:Number — Frequency to use in the x direction. For example, to generate a noise that is sized for a 64 x 128 image, pass 64 for the baseX value.
 
baseY:Number — Frequency to use in the y direction. For example, to generate a noise that is sized for a 64 x 128 image, pass 128 for the baseY value.
 
numOctaves:Number — Number of octaves or individual noise functions to combine to create this noise. Larger numbers of octaves create images with greater detail. Larger numbers of octaves also require more processing time.
 
randomSeed:Number — The random seed number to use. If you keep all other parameters the same, you can generate different pseudo-random results by varying the random seed value. The Perlin noise function is a mapping function, not a true random-number generation function, so it creates the same results each time from the same random seed.
 
stitch:Boolean — A Boolean value. If the value is true, the method attempts to smooth the transition edges of the image to create seamless textures for tiling as a bitmap fill.
 
fractalNoise:Boolean — A Boolean value. If the value is true, the method generates fractal noise; otherwise, it generates turbulence. An image with turbulence has visible discontinuities in the gradient that can make it better approximate sharper visual effects, like flames and ocean waves.
 
channelOptions:Number [optional] — A number that indicates one or more color channels. To create this value, you can use or combine any of the four color channel values: 1 (red), 2 (green), 4 (blue), and 8 (alpha). You can combine the channel values by using the logical OR operator; for example, you can combine the red and green channels by using the following code: 1 | 2.
 
grayScale:Boolean [optional] — A Boolean value. If the value is true, a grayscale image is created by setting each of the red, green, and blue color channels to identical values. The alpha channel value is not affected if this value is set to true. The default value is false.
 
offsets:Object [optional] — An array of points that correspond to x and y offsets for each octave. By manipulating the offset values you can smoothly scroll the layers of a perlinNoise image. Each point in the offset array affects a specific octave noise function.

Example
The following example shows how to apply Perlin noise to a BitmapData object.
import flash.display.BitmapData;

var bitmapData_1:BitmapData = new BitmapData(100, 80, false, 0x00CCCCCC);
var bitmapData_2:BitmapData = new BitmapData(100, 80, false, 0x00FF0000);

var mc_1:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc_1.attachBitmap(bitmapData_1, this.getNextHighestDepth());

var mc_2:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc_2.attachBitmap(bitmapData_2, this.getNextHighestDepth());
mc_2._x = 101;

mc_1.onPress = function() {
    var randomNum:Number = Math.floor(Math.random() * 10);
        bitmapData_1.perlinNoise(100, 80, 6, randomNum, false, true, 1, true, null);
}

mc_2.onPress = function() {
    var randomNum:Number = Math.floor(Math.random() * 10);
        bitmapData_2.perlinNoise(100, 80, 4, randomNum, false, false, 15, false, null);
}

pixelDissolve()method 
public function pixelDissolve(sourceBitmap:BitmapData, sourceRect:Rectangle, destPoint:Point, [randomSeed:Number], [numberOfPixels:Number], [fillColor:Number]):Number

Player version: Flash Player 8

Performs a pixel dissolve either from a source image to a destination image or by using the same image. Flash Player uses a randomSeed value to generate a random pixel dissolve. The return value of the function must be passed in on subsequent calls to continue the pixel dissolve until it is finished.

If the source image does not equal the destination image, pixels are copied from the source to the destination using all of the properties. This allows dissolving from a blank image into a fully populated image.

If the source and destination images are equal, pixels are filled with the color parameter. This allows dissolving away from a fully populated image. In this mode, the destination point parameter is ignored.

Parameters
sourceBitmap:BitmapData — The input bitmap image to use. The source image can be a different BitmapData object or it can refer to the current BitmapData instance.
 
sourceRect:Rectangle — A rectangle that defines the area of the source image to use as input.
 
destPoint:Point — The point within the destination image (the current BitmapData instance) that corresponds to the upper-left corner of the source rectangle.
 
randomSeed:Number [optional] — The random seed to use to start the pixel dissolve. The default value is 0.
 
numberOfPixels:Number [optional] — The default is 1/30 of the source area (width x height).
 
fillColor:Number [optional] — An ARGB color value that you use to fill pixels whose source value equals its destination value. The default value is 0.

Returns
Number — The new random seed value to use for subsequent calls.

Example
The following example uses pixelDissolve() to convert a grey BitmapData object to a red one by dissolving 40 pixels at a time until all 8000 pixels have changed colors:
import flash.display.BitmapData;
import flash.geom.Point;

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

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc.attachBitmap(myBitmapData, this.getNextHighestDepth());

mc.onPress = function() {
    var randomNum:Number = Math.floor(Math.random() * 10);
    dissolve(randomNum);
}

var intervalId:Number;
var totalDissolved:Number = 0;
var totalPixels:Number = 8000;

function dissolve(randomNum:Number) {
    var newNum:Number = myBitmapData.pixelDissolve(myBitmapData, myBitmapData.rectangle, new Point(0, 0), randomNum, 40, 0x00FF0000);
    clearInterval(intervalId);
    if(totalDissolved < totalPixels) {
        intervalId = setInterval(dissolve, 10, newNum);
    }
    totalDissolved += 40;
}

scroll()method 
public function scroll(x:Number, y:Number):Void

Player version: Flash Player 8

Scrolls an image by a certain (x, y) pixel amount. Edge regions outside the scrolling area are left unchanged.

Parameters
x:Number — The amount by which to scroll horizontally.
 
y:Number — The amount by which to scroll vertically.

Example
The following example shows how to scroll a BitmapData object.
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, 25, 80), 0x00FF0000);

mc.onPress = function() {
    myBitmapData.scroll(25, 0);
}

setPixel()method 
public function setPixel(x:Number, y:Number, color:Number):Void

Player version: Flash Player 8

Sets the color of a single pixel of a BitmapData object. The current alpha channel value of the image pixel is preserved during this operation. The value of the RGB color parameter is treated as an unmultiplied color value.

Parameters
x:Number — The x position of the pixel whose value changes.
 
y:Number — The y position of the pixel whose value changes.
 
color:Number — The RGB color to which to set the pixel.

See also


Example
The following example uses the setPixel() method to assign a RGB value to a pixel at a specific x and y position. You can draw on the created bitmap in 0x000000 by dragging.
import flash.display.BitmapData;

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

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc.attachBitmap(myBitmapData, this.getNextHighestDepth());

mc.onPress = function() {
    this.onEnterFrame = sketch;
}

mc.onRelease = function() {
    delete this.onEnterFrame;
}

function sketch() {
    myBitmapData.setPixel(_xmouse, _ymouse, 0x000000);
}

setPixel32()method 
public function setPixel32(x:Number, y:Number, color:Number):Void

Player version: Flash Player 8

Sets the color and alpha transparency values of a single pixel of a BitmapData object. This method is similar to the setPixel() method; the main difference is that the setPixel32() method takes an ARGB color value that contains alpha channel information.

Parameters
x:Number — The x position of the pixel whose value changes.
 
y:Number — The y position of the pixel whose value changes.
 
color:Number — The ARGB color to which to set the pixel. If you created an opaque (not a transparent) bitmap, the alpha transparency portion of this color value is ignored.

See also


Example
The following example uses the setPixel32() method to assign an ARGB value to a pixel at a specific x and y position. You can draw on the created bitmap in 0x000000 without an alpha value by pressing you mouse button and dragging.
import flash.display.BitmapData;

var myBitmapData:BitmapData = new BitmapData(100, 80, true, 0xFFCCCCCC);

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc.attachBitmap(myBitmapData, this.getNextHighestDepth());

mc.onPress = function() {
    this.onEnterFrame = sketch;
}

mc.onRelease = function() {
    delete this.onEnterFrame;
}

function sketch() {
    myBitmapData.setPixel32(_xmouse, _ymouse, 0x00000000);
}

threshold()method 
public function threshold(sourceBitmap:BitmapData, sourceRect:Rectangle, destPoint:Point, operation:String, threshold:Number, [color:Number], [mask:Number], [copySource:Boolean]):Number

Player version: Flash Player 8

Tests pixel values in an image against a specified threshold and sets pixels that pass the test to new color values. Using the threshold() method, you can isolate and replace color ranges in an image and perform other logical operations on image pixels.

The threshold test's logic is as follows:

if ((pixelValue & mask) operation (threshold & mask)) then
   set pixel to color
else
   if (copySource) then
      set pixel to corresponding pixel value from sourceBitmap

The operation parameter specifies the comparison operator to use for the threshold test. For example, by using "==", you can isolate a specific color value in an image. Or by using {operation: "<", mask: 0xFF000000, threshold: 0x7f000000, color: 0x00000000}, you can set all destination pixels to be fully transparent when the source image pixel's alpha is less than 0x7F. You can use this technique for animated transitions and other effects.

Parameters
sourceBitmap:BitmapData — The input bitmap image to use. The source image can be a different BitmapData object or it can refer to the current BitmapData instance.
 
sourceRect:Rectangle — A rectangle that defines the area of the source image to use as input.
 
destPoint:Point — The point within the destination image (the current BitmapData instance) that corresponds to upper-left corner of the source rectangle.
 
operation:String — One of the following comparison operators, passed as a String: "<", "<=", ">", ">=", "==", "!="
 
threshold:Number — The value that each pixel is tested against to see if it meets or exceeds the threshhold.
 
color:Number [optional] — The color value that a pixel is set to if the threshold test succeeds. The default is 0x00000000.
 
mask:Number [optional] — The mask to use to isolate a color component. The default value is 0xFFFFFFFF.
 
copySource:Boolean [optional] — A Boolean value. If the value is true, pixel values from the source image are copied to the destination when the threshold test fails. If the value is false, the source image is not copied when the threshold test fails. The default value is false.

Returns
Number — The number of pixels that were changed.

Example
The following example shows how to change the color value of pixels whose color value is greater than or equal to a certain threshold.
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;

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, 80), 0x00FF0000);

mc.onPress = function() {
    myBitmapData.threshold(myBitmapData, new Rectangle(0, 0, 100, 40), new Point(0, 0), "==", 0x00CCCCCC, 0x000000FF, 0x00FF0000, false);
}