How to merge two images into one using Actionscript

简介:

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// we'll scale the first ( background ) image by 50%
var s : Number = . 5 ;
 
// create a matrix to make the scalilng of the bitmap possible
var scaleMatrix : Matrix = new Matrix();
 
// apply the scaling to the matrix
scaleMatrix.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 content and scale it using the matrix
scaledBitmap.draw(bmp,scaleMatrix);
 
// we have an embedded asset called "flickr" , a flickr logo in gif format
var icon  : Bitmap = new flickr() as Bitmap;
 
// let's place it in the bottom  right  corner
var 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 ix and ij variables in the parameters
var positionMatrix : Matrix = new Matrix( 1 , 0 , 0 , 1 ,ix,ij);
 
// draw the icon  bmp to the bitmapdata
scaledBitmap.draw( icon , positionMatrix );
 
// add the new, merged, bitmap to your displaylist
var bmp : Bitmap = new Bitmap( scaledBitmap );
addChild( bmp );
 
// that's it!<br>

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!

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




    本文转自 OldHawk  博客园博客,原文链接:http://www.cnblogs.com/taobataoma/archive/2010/12/24/1916216.html,如需转载请自行联系原作者




相关文章
|
前端开发
vuecli3打包报警告:chunk chunk-common [mini-css-extract-plugin] Conflicting order.
vuecli3打包报警告:chunk chunk-common [mini-css-extract-plugin] Conflicting order.
192 0
vuecli3打包报警告:chunk chunk-common [mini-css-extract-plugin] Conflicting order.
|
7月前
135Echarts - 路径图(Use lines to draw 1 million ny streets.)
135Echarts - 路径图(Use lines to draw 1 million ny streets.)
17 0
|
8月前
|
索引
RxSwift操作符merge、zip、combinLatest的使用
RxSwift操作符merge、zip、combinLatest的使用
245 0
|
机器学习/深度学习 编解码 机器人
Paper:《First Order Motion Model for Image Animation》翻译与解读
Paper:《First Order Motion Model for Image Animation》翻译与解读
Paper:《First Order Motion Model for Image Animation》翻译与解读
使用Adobe Lifecycle ES将若干个word合并成一个PDF
使用Adobe Lifecycle ES将若干个word合并成一个PDF
使用Adobe Lifecycle ES将若干个word合并成一个PDF
|
机器学习/深度学习 数据可视化 机器人
Paper:《First Order Motion Model for Image Animation》翻译与解读(一)
Paper:《First Order Motion Model for Image Animation》翻译与解读
|
编解码 机器人 测试技术
Paper:《First Order Motion Model for Image Animation》翻译与解读(二)
Paper:《First Order Motion Model for Image Animation》翻译与解读
Google Image Search Explained
Google put the "Search by image" feature on its homepage, through which you can find similar images to any image on the internet.
2270 0