Tutorial
The Macromedia Flash8 Image API describes the new attributes of a new Actionscirpt class class BitmapData and the various methods associated with it. These new methods enable flash developers to create and manipulate 32-bit images at run time through ActionScript. These image APIs are very similar to the Lingo APIs in the Macromedia Product director. However, the image API in Flash8 is more carefully prepared and has a stronger function. In this article, we will look at how to start using the image API and discuss some of its capabilities.
Using bitmaps in ActionScript
The new BitmapData class is used to describe the bitmap object in memory, and when you create a new class instance, an empty image is saved in memory. You can use the various methods provided by the BitmapData class to manipulate this primitive bitmap. Before you start applying the BitmapData class, you need to know about bitmaps.
Bitmap is a digital format graphic that uses a color data grid to describe an image, each cell in the grid represents a pixel, and each pixel is an image rendered by a specified color value. Bitmap is saved to 32-bit color depth in Flash Player. This means that each pixel that is assigned a color is saved as a binary number, and its length is 32bit. The color of one pixel in a 32-bit image it may be just one of 167,000 colors. Each color is made up of four color channels, such as red, green, blue, and alpha channels.
This tutorial uses the BitmapData class to obtain the bitmap color code, as to how this class is used, please refer to other related tutorials.
The final effect is as follows:
Click here to download the source file
First prepare a picture, then adjust the properties of the flash document so that the high and wide fit, and then import into the library, double-click Modify the properties of the picture.
Then create a new movie clip symbol sample, draw a black rectangle.
Then create a new movie element Colorinfo, drag the top of the movie element over, give an instance name.
Then create a dynamic text box.
Place the Colorinfo movie symbol in the lower-right corner of the scene, name the instance name Selectedcolor, and then create a new layer.
Enter the following code.
Import Flash.display.bitmapdata;//import Bitmaodata class
Linkageid = "Landscape";//link to the picture identifier
Mybitmapdata = Bitmapdata.loadbitmap (Linkageid);
MC = This.createemptymovieclip ("MC", 1);
Mc.attachbitmap (Mybitmapdata, 1);
OnMouseMove = function () {
Mynewcolor = "0x" + mybitmapdata.getpixel (_xmouse,_ymouse). toString (16);
Newcolor.setrgb (Mynewcolor);
SelectedColor.colorValue.text = Mynewcolor;
}
Selectedcolor.swapdepths (_root.getnexthighestdepth ());
Newcolor = new Color (selectedcolor.sample);
Press Ctrl+enter to test it! (The code is very well understood!) If you don't understand, you can check out the article specifically about the BitmapData class.