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