Research on flash bitmap Technology (5): Ghost painting

Source: Internet
Author: User
Tags addchild

 

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 );

}
}
}






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.