Posted By

adrianparr on 02/20/12


Tagged

get png mask rectangle bitmapData as3 rect visible getColorBoundsRect getBounds bounds masked


Versions (?)

AS3 getVisibleBounds


 / Published in: ActionScript 3
 

URL: http://plasticsturgeon.com/2010/09/as3-get-visible-bounds-of-transparent-display-object/

All credit for this goes to Zach Foley (aka Plastic Sturgeon)

  1. package util
  2. {
  3. import flash.display.DisplayObject;
  4. import flash.display.BitmapData;
  5. import flash.geom.Rectangle;
  6. import flash.geom.Matrix;
  7. public function getVisibleBounds(source:DisplayObject):Rectangle
  8. {
  9. // Updated 11-18-2010;
  10. // Thanks to Mark in the comments for this addition;
  11. var matrix:Matrix = new Matrix()
  12. matrix.tx = -source.getBounds(null).x;
  13. matrix.ty = -source.getBounds(null).y;
  14.  
  15. var data:BitmapData = new BitmapData(source.width, source.height, true, 0x00000000);
  16. data.draw(source, matrix);
  17. var bounds : Rectangle = data.getColorBoundsRect(0xFFFFFFFF, 0x000000, false);
  18. data.dispose();
  19. return bounds;
  20. }
  21. }

Report this snippet  

You need to login to post a comment.