将多个位图/光栅图像动态组合成一个

时间:2012-08-20 03:01:55

标签: flex actionscript air

我正在创建一个Air / flex应用程序,通过相机捕获多个图像。现在我有了图像,我想将几​​个捕获的图像“粘贴”在另一个图像(我的主图像)上的预定义位置上。谁能提供一个例子或指出我正确的方向?。

2 个答案:

答案 0 :(得分:1)

您可以将此代码粘贴到项目中进行测试,评论会逐步显示其工作原理。希望这就是你所需要的!

import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.display.Bitmap;

// This rectangle represents your photo: 500x500, pure red.
var myPhoto:BitmapData = new BitmapData (500,500,false,0xff0000)
// This is another photo (green rectangle) as Bitmapdata, also 500x500 px
var somethingToDrawOnTop:BitmapData = new BitmapData (500,500,false, 0x00ff00)
// Select a region of the green picture: a 50x50 region located at 100,100 of the green pic
var regionToCopy:Rectangle = new Rectangle(100,100,50,50)
// Decide where you want the copied green region to end up in the red picture
var destinationForTheCopy:Point = new Point(250,250)
// Copy the pixels
myPhoto.copyPixels(somethingToDrawOnTop, regionToCopy, destinationForTheCopy)

// show the result
var compositBitmap:Bitmap = new Bitmap(myPhoto)
addChild (compositBitmap)

答案 1 :(得分:0)