Flash 8 copy pixels bitmap pixel copy

Source: Internet
Author: User
Tags empty

Flash 8 Professional copy pixels bitmap pixel copy
Author:allan
Reprint please indicate the source:Allan.blog ()

In addition to the various simple filter filters in Flash 8, a very powerful pixel operation is provided for BitmapData bitmap objects. Of course, with pixel-level operations, the most direct use is that we can directly control each point in the bitmap, change his color, location, can directly create their own rich filters, of course, the future is beautiful, we must pay attention to the implementation of efficiency, although the efficiency of Flash Player8 has been greatly improved, However, I am still in the test of various pixel operations mistakenly large operation and panic ....

Today's example is the simplest one to get the pixel and copy it into a new object, but with this feature, there is no limit to the likelihood of bitmap manipulation.

Import flash.display.*;
Import flash.geom.*;
Two pageage required to import this example

var sourcebd:bitmapdata = Bitmapdata.loadbitmap ("Mypic");
Create a BitmapData object for storing the source picture, which is already in the library and named Mypic

var mc:movieclip = This.createemptymovieclip ("MC", This.getnexthighestdepth ());
mc._x = 25;
mc._y = 100;
Mc.attachbitmap (Sourcebd,mc.getnexthighestdepth ());
Create an empty MC on the stage and use the MC's Attachbitmap method to read the BitmapData object that you just created into this MC

var targetbd:bitmapdata = new BitmapData (230, 230, false, 111111);
Create another BitmapData object as a replication destination

var mc2:movieclip = This.createemptymovieclip ("MC", This.getnexthighestdepth ());
mc2._x = 290;
mc2._y = 100;
Mc2.attachbitmap (Targetbd,mc.getnexthighestdepth ());
Also create an empty MC on the stage to store the replication target

Mc.onrollover = function () {
When the mouse is moved to the MC with the source graph, start copypixels
CopyPixels ();
};
Mc.onrollout = function () {
Move out state Stop copy
Stopcopypixels ();
};
Copy Pixels Function
function CopyPixels () {
This.onmousemove = function () {
SetCursor ()//Set mouse cursor
var point:point = new Point (_xmouse, _ymouse);
Mc.globaltolocal (point);
Get the current mouse seat and use globaltolocal to convert the coordinate value inside the MC
var rect:rectangle = new Rectangle (Point.x, Point.y, 20, 20);
/* Create a Rectangle object to determine which rectangular area to copy
The Rectangle object is a new object in the Flash8, where the package is positioned in addition to the Rectangle rectangular data object, and other object types for storing geometry data, including point, Tranform, etc.
Rectangle is constructed in the form of
Public Rectangle (X:number, Y:number, Width:number, Height:number)
X,y: Starting seat
Width,height: The width and height of the rectangle will eventually create a rectangular region of data from X,y to X+width,y+height
*/
var dest:point = new Point (Point.x, POINT.Y);
Establish a Dest object for storing target points
Targetbd.copypixels (sourcebd,rect,dest);
/* This is the key method for this example, copypixels, to copy pixels from a region in the source diagram to the current object
The construction mode is public copypixels (Sourcebitmap:bitmapdata, Sourcerect:rectangle, Destpoint:point, Alphabitmap:bitmapdata, Alphapoint:point, Mergealpha:boolean)
Sourcebitmap: The source diagram that needs to be copied, the BitmapData object type, is applied here to the previously established SOURCEBD
Sourcerect: Replicating regions
Deskpoint: Target point, explicitly copy the area to which location of this object, in this case, the location of the pixel where the source graph is completely restored

The following several parameters are not used in this example
Alphabitmap and Alphapoint: Indicates that another image can be used to generate an alpha channel for the source diagram at the time of replication to create a copy result with an alpha channel effect.
Mergealpha attribute refers to whether to enable the source map of the alpha-map, but there is no specific effect of debugging, pending further study. * *
};
}
function Stopcopypixels () {
Stop CopyPixels
Clearcursor ();
Delete This.onmousemove;
}
function SetCursor () {
Set the mouse to square pattern
Sourcecursor_mc.swapdepths (_root.getnexthighestdepth ());
Sourcecursor_mc.startdrag (TRUE);
Targetcursor_mc.swapdepths (_root.getnexthighestdepth ());
targetcursor_mc._x = sourcecursor_mc._x+265;
targetcursor_mc._y = sourcecursor_mc._y;
Mouse.hide ();
}
function Clearcursor () {
Restore Mouse
Sourcecursor_mc.stopdrag ();
sourcecursor_mc._x =-50;
sourcecursor_mc._y =-50;
targetcursor_mc._x =-50;
targetcursor_mc._y =-50;
Mouse.show ();
}

Examples of copying with alpha channel images

Need Flash Player 8 [ source file download, need Flash 8]

The example is simple, but it seems to be a clumsy form of the Photoshop stamp function. Of course, if the use of flash to make stamp function, more multi-functional can be dug out, you can copy the time to copy only a certain color ... or copy directly to a monochrome picture ... Or... Xxxx.



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.