How to merge two images into one using ActionScript

Source: Internet
Author: User

W ell, it's very easy, using bitmapdata and bitmap. this example makes things a bit more complex to show some principles. hope you learn something out of it off course.

// We'll scale the first (background) image by 50% var S: Number =. 5; // create a matrix to make the scalilng of the bitmap possiblevar scalematrix: matrix = new matrix (); // apply the scaling to the matrixscalematrix. scale (S, S); // create a bitmapdata object from an existing Bitmap ("BMP" in this case) var scaledbitmap: bitmapdata = new bitmapdata (BMP. width * s, BMP. height * s, false, 0); // draw the C Ontent and scale it using the matrixscaledbitmap. draw (BMP, scalematrix); // we have an embedded asset called "Flickr", a Flickr logo in GIF formatvar icon: bitmap = new Flickr () as bitmap; // Let's place it in the bottom right cornervar IX: Number = scaledbitmap. width-icon.width; var IJ: Number = scaledbitmap. height-icon.height; // create a matrix for the position of the icon // note the use of the I X and IJ variables in the parametersvar positionmatrix: matrix = new matrix (1, 0, 1, IX, IJ); // draw the icon BMP to the bitmapdatascaledbitmap. draw (icon, positionmatrix); // Add the new, merged, bitmap to your displaylistvar BMP: bitmap = new Bitmap (scaledbitmap); addchild (BMP ); // that's it!

PS: As per user comments I 've also uploaded an example to use in the Flash IDE (*. FLA file)-the above example assumes you're using flash builder or another Editor

I do have to say I don't understand why people try to merge two bitmaps in Flash using the IDE. you coshould just as easily create a movieclip with the two bitmaps on top of each other. or am I missing something? Tell me in the comments!

Download the example *. FLA file here: http://www.webdevotion.be/blog/wp-content/mergy.fla.zip

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.