<< Chapter < Page Chapter >> Page >

The JPEG format does not support alpha transparency. Therefore, it is not suitable as a file format for transmitting images with alpha data betweencomputers.

The PNG format

Apparently there are some patent issues with the GIF format. The Portable Network Graphics (PNG) format was produced as an open-source alternative to the GIF file format.

The PNG format supports at least sixteen million colors and uses lossless compression. The PNG format also supports alpha transparency allowing for up to256 levels of transparency in a compressed format.

The BitmapData class

The BitmapData class in ActionScript 3 supports a 32-bit ARGB color model with more than sixteen million colors and 256 levels of alphatransparency per pixel.

Preview

I will explain two different programs in this lesson. One is named Bitmap05 and the other is named Bitmap06 . Both programs produce the same output, which is shown in Figure 1.

Screen output for both programs.

Missing image
Screen output for both programs.

Program file structure

Figure 2 shows the program file structure taken from the Flex Builder 3 Navigator panel for the program named Bitmap05 .

Program file structure for the program named bitmap05.

Missing image
Program file structure for the program named Bitmap05.

The program file structure for Bitmap06 is the same except for the name of MXML file.

I will use the programs named Bitmap05 and Bitmap06 to explain a variety of topics.

Skeleton code

First, I will provide skeleton code for creating a Bitmap object from an image file. You will learn how to use the skeleton code to create and display a bitmap from an image file as shown by the top image in Figure 1.

Extract the BitmapData object

I will show you how to extract the BitmapData object from the Bitmap object so that you can modify the pixels in the image. Once you are able to extract the BitmapData object, you will have the bitmap data exposed to the point that you can implement a varietyof image processing algorithms such as the following:

  • Smoothing
  • Sharpening
  • Edge detection
  • Color filtering
  • Color inversion
  • Redeye correction

(For more information on how to implement image processing algorithms in general, see the tutorial lessons beginning with Lesson 340 in the sectiontitled Multimedia Programming with Java on my web site .)

Using the getPixels, setPixels, and setPixel32 methods

I will explain how to use the getPixels , setPixels , and setPixel32 methods for modifying the pixels in a bitmap as shown by the middle image in Figure 1. Ifyou compare the middle image with the top image, you will see that two colored bars were added near the upper-left corner. In addition, colored borders wereadded to the middle image.

Color inversion

Finally, I will explain how to implement a color inversion algorithm as shown by the bottom image in Figure 1. If you compare the bottom image with the middleimage, you will see that the colors of all of the pixels in the top half of the bottom image have been changed. The colors of the pixels were changed using aparticular algorithm known widely as a color inversion algorithm.

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