<< Chapter < Page Chapter >> Page >

On the other hand...

On the other hand, had we wanted to do something like emphasize the green color and deemphasize the blue color in the rectangular region, we would haveneeded to call the getPixels method to get the actual pixel data from the BitmapData object into the array. Having that pixel data available, we could have:

  • Multiplied the green color value in each pixel by 1.2,
  • Multiplied the blue color values in each pixel by 0.8,
  • Called the setPixels method as in Listing 11 to store the modified pixel data back into the same rectangular region of the BitmapData object.

Process pixels using the setPixel32 method

The code in Listing 12 uses the setPixel32 method to put a magenta border on the left edge of the bitmap and a cyan border on the right edge of the BitmapData object as shown in the middle image in Figure 1. (The border is two pixels thick.)

Process pixels using the setpixel32 method.

for(var row:uint = 0;row<bitmapData.height; row++){bitmapData.setPixel32(0,row,0xFFFF00FF); bitmapData.setPixel32(1,row,0xFFFF00FF);bitmapData.setPixel32(bitmapData.width - 1,row,0xFF00FFFF); bitmapData.setPixel32(bitmapData.width - 2,row,0xFF00FFFF); }//end for loop

The setPixel32 method and its cousins

The setPixel32 method and its cousin the setPixel method, along with the getPixel32 method and the getPixel method, are completely different from the getPixels method and the setPixels method used earlier.

And the differences are...

Each call to the getPixels method or the setPixels method deals with all of the pixels in a specified rectangular region.

Each call to the getPixel method, the getPixel32 method, the setPixel method, or the setPixel32 method deals with only one pixel. That pixel is identified by the horizontal and vertical coordinates of a single pixel in the BitmapData object.

Getting and/or setting a pixel value

As you have probably guessed by now, the getPixel and getPixel32 methods are used to return the value of a single pixel from the specified location. Both of these methods return a 32-bit datavalue of type uint .

Similarly, the setPixel and setPixel32 methods are used to write a 32-bit unsigned integer value into a specified location in the BitmapData object.

Not decomposed into separate bytes

Unlike with the getPixels method used with the ByteArray object, the getPixel and getPixel32 methods don't decompose the 32-bit integer value into separate bytes for alpha, red, green, and blue. If you need to separate thereturned value into individual bytes, you must accomplish that yourself.

The order of the bytes in the returned value is ARGB. In other words, the leftmost eight bits contain the alpha value, the rightmost eight bits containthe blue value, and the red and green bytes are in the middle.

The difference between the methods

The difference between the methods with 32 in the name the methods without 32 in the name has to do with the alpha byte. The two methods without 32 in thename return a 32-bit unsigned integer but only the 24 RGB bits are meaningful. The eight alpha bits are not meaningful. On the other hand, for the methods with32 in the name, all four bytes including the alpha byte are meaningful.

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