<< Chapter < Page Chapter >> Page >

Set the pixels to create a border

The code in Listing 12 uses a for loop and the setPixel32 method to set the pixel color to fully opaque magenta (red plus blue) for the first two pixels in each row of pixels and to set the pixel color to fully opaque cyan (green plus blue) for the last two pixels in each row. This produces a magenta border with a thickness of twopixels on the left edge of the middle image in Figure 1 and produces a cyan border with a thickness of two pixels on the right edge of the middle image inFigure 1.

Put borders on the top and bottom edges

Listing 13 uses similar code to put a cyan border along the top edge and a magenta border along the bottom edge of the middle image in Figure 1.

Put borders on the top and bottom edges.

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

The end of the modify method

Listing 13 also signals the end of the modify method. When the method returns from the call that was made in Listing 7, the pixels in thered and green rectangular region near the upper-left corner of the middle image of Figure 1 have been modified relative to the original image shown in the topimage in Figure 1. In addition, the pixels along all four edges of the middle image have been replaced by magenta and cyan pixels to produce a border with athickness of two pixels.

Return to the complete event handler

Returning now to where we left off in the complete event handler in Listing 7, the code in Listing 14:

  • Creates another duplicate BitmapData object.
  • Encapsulates it in an Image object.
  • Places it at the bottom of Figure 1.
  • Calls the modify method to modify the pixels just like the middle image in Figure 1.
  • Calls the invert method to invert the colors of all the pixels in the top half of the BitmapData object to produce the final image shown at the bottom of Figure 1.

Return to the complete event handler.

//Clone the original bitmap to create another // duplicate.var duplicateC:Bitmap = new Bitmap( original.bitmapData.clone());//Place the duplicateC below the other two in the // VBox.duplicateC.x = 5; duplicateC.y = 2*original.height;var imageC:Image = new Image();imageC.addChild(duplicateC); this.addChild(imageC);//Modify the pixels as above to add some color to// the image. modify(duplicateC);//Now invert the colors in the top half of this // bitmap. Note that the magenta and green colors// swap positions. invert(duplicateC);} //end completeHandler

Color inversion

The color inversion algorithm is

  • Very fast to execute.
  • Totally reversible.
  • Guaranteed to convert every pixel to a different color.

Usually the new color is readily distinguishable from the old color.

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