Flash as 3.0 achieves online graph cutting

Source: Internet
Author: User
Tags transparent image
Recently, bitmapData is needed to crop images. We have used transparent pixel-based rubber bands for a long time. The image cropping principle is the same as that of the rubber band. It may have been useless for a long time and out of strangers, so I decided to do it well and deepen my impression. Haha...

(Double-click the heart above to generate an image)


The following is the core code of image cropping:
Function cutLayer_doubleClick_handler (me: MouseEvent)

CutBtn. mouseEnabled = true;
IsCut = false
Itf. actionExit (); // The Exit Action of scaling and editing an object

// Temp_bmi is mainly used to obtain alphaBitmapData during copyPixels (). In a simple sense, it is obtained from irregular images on the masking layer.
Var temp_bmi: BitmapData = new BitmapData (org_sprite.width, org_sprite.height, true, 0)
// Compare_bmi is the pixel image copied from the source bitmapData on the masking layer (irregular image).
Var compare_bmi: BitmapData = new BitmapData (org_sprite.width, org_sprite.height, true, 0)

// Specifies the displacement, scaling, and rotation of the image on the photo masking layer.
Var temp_matrix: Matrix = new Matrix ();

Temp_matrix.scale (cut_layer.scaleX, cut_layer.scaleY );
Temp_matrix.rotate (cut_layer.rotation/180 * Math. PI );
Temp_matrix.translate (cut_layer.x, cut_layer.y );

// Because the photo masking layer uses a Mc and a transparent image, if you do not set alphaBitmapData to the maximum transparency when copyPixels is used, the transparency of the copy image is the same as that of alphaBitmapData.
Var temp_ctf: ColorTransform = new ColorTransform ()
Temp_ctf.alphaOffset = 255

// Draw an irregular shadow layer
Temp_bmd.draw (cut_layer, temp_matrix, temp_ctf );

// Copy pixels
Compare_bmd.copyPixels (org_bmi,
Org_sprite.getBounds (this ),
New Point (0, 0 ),
Temp_bmi,
New Point (0, 0 ),
False );

// Display the copied image
Compare_bm.bitmapData = compare_bmi;
}

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.