Guest User

Untitled

a guest
Jul 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. public static function cloneDpObj(target:DisplayObject):Bitmap
  2. {
  3. var duplicate:Bitmap;
  4.  
  5. var tBitData:BitmapData = new BitmapData(target.width, target.height);
  6. tBitData.draw(target);
  7. duplicate = new Bitmap(tBitData);
  8.  
  9. return duplicate;
  10. }
  11.  
  12. // bounds and size of parent in its own coordinate space
  13. var rect:Rectangle = target.parent.getBounds(target.parent);
  14. var bmp:BitmapData = new BitmapData(rect.width, rect.height, true, 0);
  15.  
  16. // offset for drawing
  17. var matrix:Matrix = new Matrix();
  18. matrix.translate(-rect.x, -rect.y);
  19.  
  20. // Note: we are drawing parent object, not target itself:
  21. // this allows to save all transformations and filters of target
  22. bmp.draw(target.parent, matrix);
  23.  
  24. public static function cloneDpObj(target:DisplayObject):Bitmap
  25. {
  26. var duplicate:Bitmap;
  27.  
  28. var tBitData:BitmapData = new BitmapData(target.width, target.height);
  29. tBitData.draw(target);
  30. duplicate = new Bitmap(tBitData);
  31. //add the filters
  32. duplicate.filters = target.filters;
  33.  
  34. return duplicate;
  35. }
  36.  
  37. public static function cloneDpObj(target:DisplayObject, optWidth:Number = -1, optHeight:Number = -1):Bitmap
  38. {
  39. var duplicate:Bitmap;
  40.  
  41. if (!target.parent) {
  42. var tempSprite:Sprite = new Sprite;
  43. tempSprite.addChild(target);
  44. }
  45.  
  46. var rect:Rectangle = target.parent.getBounds(target.parent);
  47. var bmp:BitmapData = new BitmapData(rect.width + 1, rect.height, true, 0);
  48.  
  49. // offset for drawing
  50. var matrix:Matrix = new Matrix();
  51. matrix.translate( -rect.x, -rect.y);
  52.  
  53. // Note: we are drawing parent object, not target itself:
  54. // this allows to save all transformations and filters of target
  55. bmp.draw(target.parent, matrix);
  56.  
  57. duplicate = new Bitmap(bmp);
  58.  
  59. return duplicate;
  60. }
Add Comment
Please, Sign In to add comment