Today, I visited some foreign blogs on Bitmap applications, and found that bitmap operations will produce a lot of results. One of them is the implementation of Bitmap, with the help of this pixel operation on bitmap, combine the new image and combine it into a new image.
The idea is simple. Using this method will be of great help to some extent. Such as aggregation and scattered pixel animation.
The left side is a normal image, while the right side is a pixel-processed gray wolf image.
You can obtain the data source from an externally loaded image. Through this data source, you can use the bitmapdata class to obtain the pixel value. Each pixel contains the rbg value, through getpixel (X, y) the bitmap can be acquired in pixels. Then fill in. Finally, the image in the right pixel is generated. The main method applications involved are:
Two cycles are used to obtain the pixel value.
// Retrieve and reorganize pixels
For (var I: Int = 0; I <width; I + = step)
{
For (var j: Int = 0; j {
VaR color: uint = BMP data. getpixel (I, j );
VaR rect: rectangle = new rectangle (I, j, step, step );
BMP data. fillrect (rect, color); // fill the pixel
}
}
The following is the implementation process. You can use the getpixel method.
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 ";
Private var step: Int = 5;
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 + = step)
{
For (var j: Int = 0; j {
VaR color: uint = BMP data. getpixel (I, j );
VaR rect: rectangle = new rectangle (I, j, step, step );
BMP data. fillrect (rect, color); // fill the pixel
}
}
// Display to the list menu
VaR bitmap: bitmap = new Bitmap (BMP data );
Bitmap. x = width;
Addchild (Bitmap );
}
}
}