Well, 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.
<code>// we'll scale the first ( background ) image by</code><code>50%</code>
<code>var s : Number = .</code><code>5</code><code>;</code>
<code>// create a matrix to make the scalilng of the bitmap possible</code>
<code>var scaleMatrix : Matrix = new Matrix();</code>
<code>// apply the scaling to the matrix</code>
<code>scaleMatrix.scale(s,s);</code>
<code>// create a bitmapdata object from an existing bitmap (</code><code>"bmp"</code> <code>in this case )</code>
<code>var scaledBitmap : BitmapData = new BitmapData(bmp.width*s,bmp.height*s,false,</code><code>0</code><code>);</code>
<code>// draw the content and scale it using the matrix</code>
<code>scaledBitmap.draw(bmp,scaleMatrix);</code>
<code>// we have an embedded asset called</code><code>"flickr"</code><code>, a flickr logo in gif</code><code>format</code>
<code>var</code><code>icon</code> <code>: Bitmap = new flickr() as Bitmap;</code>
<code>// let's place it in the</code><code>bottom</code> <code>right</code> <code>corner</code>
<code>var ix : Number = scaledBitmap.width-</code><code>icon</code><code>.width;</code>
<code>var ij : Number = scaledBitmap.height-</code><code>icon</code><code>.height;</code>
<code>// create a matrix for the position of the</code><code>icon</code>
<code>// note the use of the ix and ij variables in the parameters</code>
<code>var positionMatrix : Matrix = new Matrix(</code><code>1</code><code>,</code><code>0</code><code>,</code><code>0</code><code>,</code><code>1</code><code>,ix,ij);</code>
<code>// draw the</code><code>icon</code> <code>bmp to the bitmapdata</code>
<code>scaledBitmap.draw(</code><code>icon</code><code>, positionMatrix );</code>
<code>// add the new, merged, bitmap to your displaylist</code>
<code>var bmp : Bitmap = new Bitmap( scaledBitmap );</code>
<code>addChild( bmp );</code>
<code>// that's it!<br></code>
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 could 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!
本文轉自 OldHawk 部落格園部落格,原文連結:http://www.cnblogs.com/taobataoma/archive/2010/12/24/1916216.html,如需轉載請自行聯系原作者