Airアプリ(MovieClip / other DisplayObjectなど)内のコンテンツのスナップショットのみが必要な場合は、BitmapDataのdraw()メソッドを使用できます。
/*
* getSnapshot - simple snapshot of a DisplayObject
* @param matrix - the transformation matrix of the object to be drawn(translation/rotation/scale)
* use this parameter to include the object's tranformations or an arbitrary one.
* Ex. getSnapshot(myClip,myClip.transform.concatenatedMatrix);
* @param coordinateSpace - the coordinate space from used to get bounds. if you're object's rotated,
* the by passing null, the bitmap will include all contents, otherwise it will be
* clipped using the original/'unrotated' bounds.
*/
function getSnapshot(obj:DisplayObject,matrix:Matrix = null,coordinateSpace:DisplayObject = null):BitmapData{
var bounds:Rectangle = obj.getBounds(coordinateSpace);
var result:BitmapData = new BitmapData(bounds.width,bounds.height,true,0x00FFFFFF);
result.draw(obj,matrix);
return result;
}
例えば
var test:Shape = addChild(new Shape()) as Shape;
test.graphics.beginFill(0);test.graphics.drawRect(0,0,100,100);test.graphics.endFill();
var snapShot:Bitmap = addChild(new Bitmap(getSnapshot(test))) as Bitmap;
snapShot.x = test.width+10;
function getSnapshot(obj:DisplayObject,matrix:Matrix = null,coordinateSpace:DisplayObject = null):BitmapData{
var bounds:Rectangle = obj.getBounds(coordinateSpace);
var result:BitmapData = new BitmapData(bounds.width,bounds.height,true,0x00FFFFFF);
result.draw(obj,matrix);
return result;
}