Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static function cloneDpObj(target:DisplayObject):Bitmap
- {
- var duplicate:Bitmap;
- var tBitData:BitmapData = new BitmapData(target.width, target.height);
- tBitData.draw(target);
- duplicate = new Bitmap(tBitData);
- return duplicate;
- }
- // bounds and size of parent in its own coordinate space
- var rect:Rectangle = target.parent.getBounds(target.parent);
- var bmp:BitmapData = new BitmapData(rect.width, rect.height, true, 0);
- // offset for drawing
- var matrix:Matrix = new Matrix();
- matrix.translate(-rect.x, -rect.y);
- // Note: we are drawing parent object, not target itself:
- // this allows to save all transformations and filters of target
- bmp.draw(target.parent, matrix);
- public static function cloneDpObj(target:DisplayObject):Bitmap
- {
- var duplicate:Bitmap;
- var tBitData:BitmapData = new BitmapData(target.width, target.height);
- tBitData.draw(target);
- duplicate = new Bitmap(tBitData);
- //add the filters
- duplicate.filters = target.filters;
- return duplicate;
- }
- public static function cloneDpObj(target:DisplayObject, optWidth:Number = -1, optHeight:Number = -1):Bitmap
- {
- var duplicate:Bitmap;
- if (!target.parent) {
- var tempSprite:Sprite = new Sprite;
- tempSprite.addChild(target);
- }
- var rect:Rectangle = target.parent.getBounds(target.parent);
- var bmp:BitmapData = new BitmapData(rect.width + 1, rect.height, true, 0);
- // offset for drawing
- var matrix:Matrix = new Matrix();
- matrix.translate( -rect.x, -rect.y);
- // Note: we are drawing parent object, not target itself:
- // this allows to save all transformations and filters of target
- bmp.draw(target.parent, matrix);
- duplicate = new Bitmap(bmp);
- return duplicate;
- }
Add Comment
Please, Sign In to add comment