<< Chapter < Page Chapter >> Page >

The processChromaKey method begins in Listing 4.

Beginning of the processchromakey method.

private function processChromaKey(bitmap:Bitmap):void{ //Get the BitmapData object.var bitmapData:BitmapData = bitmap.bitmapData; //Populate a one-dimensional byte array of pixel// data from the bitmapData object. Note that the // pixel data format is ARGB.var rawBytes:ByteArray = new ByteArray(); rawBytes = bitmapData.getPixels(new Rectangle(0,0,bitmapData.width,bitmapData.height));

A reference to a Bitmap object

This method receives a reference to a Bitmap object as an incoming parameter.

It identifies all of the pixels in the incoming bitmap with a pure magenta color and sets the alpha bytes for those pixels to a value of zero.

This causes those pixels to become transparent as shown by the bottom image in Figure 1.

Nothing new in Listing 4

I explained all of the code in Listing 4 in the earlier lesson titled Fundamentals of Image Pixel Processing.

The ByteArray object is populated with pixel data

When the getPixels method returns in Listing 4, the pixels from a rectangular region that encompasses the entire bitmap are stored in the ByteArray object referred to by rawBytes .

The organization of the pixel data

The array is populated with the bitmap pixel data from the rectangular region on a row by row basis.

The first four bytes in the array belong to the pixel in the upper-left corner of the rectangular region. The next four bytes belong to the pixelimmediately to the right of that one, and so on.

Four bytes per pixel

Each set of four bytes represents one pixel in ARGB format. In other words, the first byte in the four-byte group is the alpha byte. That byte is followedby the red byte, the green byte, and the blue byte in that order.

This information is critical when time comes to use the data in the array to modify the bitmap data.

Set selected alpha values to zero

The code in Listing 5 iterates through the entire set of image pixels and sets selected alpha values to zero.

Set selected alpha values to zero.

//Declare working variables. Note that there is // no requirement to deal with the green color// value in this case of testing for magenta. var cnt:uint;var red:uint; var green:uint;var blue:uint;for (cnt = 0; cnt<rawBytes.length; cnt += 4) { //alpha is in rawBytes[cnt]red = rawBytes[cnt + 1];green = rawBytes[cnt + 2];blue = rawBytes[cnt + 3];if ((red == 255)&&(green == 0 )&&(blue == 255)) {//The color is pure magenta. Set the value// of the alpha byte to zero. rawBytes[cnt]= 0; }//end if}//end for loop

A for loop

After declaring some working variables, Listing 5 iterates through all of the data in the ByteArray object. It extracts the red, green, and blue color bytes from each four-byte group and tests to see if red and blue are bothset to full intensity with a value of 255 and green is set to zero.

If true, this is interpreted to match the magenta background color, and the value of the alpha byte in that four-bit group is set to zero.

Questions & Answers

what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with actionscript. OpenStax CNX. Jun 04, 2010 Download for free at http://cnx.org/content/col11202/1.19
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with actionscript' conversation and receive update notifications?

Ask