ADOBE FLEX 3
Developer Guide
384
The draw() method draws, or renders, the graphical content from a source sprite, movie clip, or other display object
on to a new bitmap. Using the
matrix, colorTransform, blendMode, and destination clipRect parameters, you
can modify the way in which the new bitmap is rendered. This method uses the vector renderer in Flash Player and
AIR to generate the data.
When you call
draw(), you pass the source object (sprite, movie clip, or other display object) as the first parameter,
as demonstrated here:
myBitmap.draw(movieClip);
If the source object has had any transformations (color, matrix, and so forth) applied to it after it was originally
loaded, these transformations are not copied across to the new object. If you want to copy the transformations to the
new bitmap, then you need to copy the value of the
transform property from the original object to the transform
property of the Bitmap object that uses the new BitmapData object.
Making textures with noise functions
To modify the appearance of a bitmap, you can apply a noise effect to it, using either the noise() method or the
perlinNoise() methods. A noise effect can be likened to the static that appears on an untuned television screen.
To apply a noise effect to a a bitmap, use the
noise() method. This method applies a random color value to pixels
within a specified area of a bitmap image.
This method accepts five parameters:
randomSeed (int): The random seed number that determines the pattern. Despite its name, this number actually
creates the same results if the same number is passed. To get a true random result, use the
Math.random() method
to pass a random number for this parameter.
low (uint): This parameter refers to the lowest value to be generated for each pixel (0 to 255). The default value
is 0. Setting this value lower results in a darker noise pattern, while setting it to a higher value results in a brighter
pattern.
high (uint): This parameter refers to the highest value to be generated for each pixel (0 to 255). The default value
is 255. Setting this value lower results in a darker noise pattern, while setting it to a higher value results in a brighter
pattern.
channelOptions (uint): This parameter specifies to which color channel of the bitmap object the noise pattern
will be applied. The number can be a combination of any of the four color channel ARGB values. The default value
is 7.
grayScale (Boolean): When set to true, this parameter applies the randomSeed value to the bitmap pixels,
effectively washing all color out of the image. The alpha channel is not affected by this parameter. The default value
is
false.
The following example creates a bitmap image and applies a blue noise pattern to it:
import flash.display.Bitmap;
import flash.display.BitmapData;
var myBitmap:BitmapData = new BitmapData(250, 250,false, 0xff000000);
myBitmap.noise(500, 0, 255, BitmapDataChannel.BLUE,false);
var image:Bitmap = new Bitmap(myBitmap);
addChild(image);

Get ADOBE® FLEX® 3: PROGRAMMING ACTIONSCRIPT™ 3.0 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.