Research on flash bitmap Technology (6): black and white

Source: Internet
Author: User

Continue to record the above information. The pixel painting is to reorganize each pixel, and these operations can be seen that bitmap pixel operations can change a lot of unexpected results. Today
Some articles on the website record the black and white pixel operations. The principle is very simple. From an image, we can see that it is composed of pixels and small particles. These particles contain
Some values, color values, and these values show different colors. as3 can index each pixel. Through this index, we can "start to pin" some pixels in the image ", set white in some values and black in some values.

Black: 0x000000;

White: 0 xffffff;

In this way, the effects of black and white images can be achieved.

The effect of the demo.



Package
{
Import flash. display. Sprite;
Import flash. display. loader;
Import flash. display. Bitmap;
Import flash. display. bitmapdata;
Import flash. Events .*;
Import flash.net .*;
Import flash. Geom. rectangle;
Public class main extends Sprite
{
Private var Loader: loader;
Private var URL: String = "3.jpg ";
Public Function main ()
{
Init ();
}
// Initialization
Private function Init (): void
{
Loader = new loader (); // loads an image externally
Loader. Load (New URLRequest (URL ));
Loader. contentloaderinfo. addeventlistener (event. Complete, oncomplete );
}
Private function oncomplete (Event: Event): void
{

VaR width: Number = loader. content. width;
VaR height: Number = loader. content. height;
Addchild (New Bitmap (loader. Content). bitmapdata ));

VaR BMP data: bitmapdata = new bitmapdata (width, height, false, 0 xffffff); // create a blank bitmap data
BMP data. Draw (loader); // obtain the image

// Retrieve and reorganize pixels
For (var I: Int = 0; I <width; I ++)
{
For (var j: Int = 0; j {
VaR color: uint = BMP data. getpixel (I, j );
If (color> 0x3fffff)
BMP data. setpixel (I, j, 0 xffffff); // set the white color.
Else BMP data. setpixel (I, j, 0x000000); // sets the black color.
}
}
// Display to the list menu
VaR bitmap: bitmap = new Bitmap (BMP data );
Bitmap. x = width;
Addchild (Bitmap );

}
}
}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.