To create and display a brand new bitmap image, follow these steps:
Create a BitmapData object.
Set the BitmapData object's pixel colors as desired.
Associate the BitmapData object with a Bitmap object.
Add the Bitmap object to the display list.
Let's try it out!
Our goal is to display a 10 × 10 blue square centered on a 20 × 20 green background. First, we'll create the BitmapData object using the following general code:
height parameters indicate the pixel
dimensions of the image, which have a maximum value of 2880. The image
dimensions cannot be changed after the BitmapData object is created. The
transparent parameter indicates whether the
image should support per-pixel transparency (i.e., whether the Alpha
channel of each pixel's color value can be set to anything less than
255). If the image does not need to be transparent, then
transparent should be set to
false because the Flash runtime renders
opaque bitmaps faster than transparent ones. Finally, the
fillColor parameter indicates the color
value that is initially assigned to all pixels in the image.
The image we want to create is 20 × 20 pixels square, does not require transparency, and has a green background. Hence, to create our BitmapData object, we use the following code:
// 0xFF00FF00 means Alpha: 255, Red: 0, Green: 255, Blue: 0 var imgData:BitmapData = new BitmapData(20, 20, false, 0xFF00FF00);
Next, we need to set the color of a 10 ...