Posted By

tinytiger on 08/07/12


Tagged

flash


Versions (?)

Return trimmed bounding box of bitmap


 / Published in: ActionScript 3
 

This function returns the trimmed bounding box of a bitmap which contains all non-transparent pixel which color values are higher than the specified treshold (default 0xFF333333 in ARGB notation).

  1. private function trimTransparency(bmp:Bitmap, treshold:uint = 0xFF333333):Rectangle {
  2.  
  3. // Clone the orignal with a clear background
  4. var clone:BitmapData = new BitmapData(bmp.width, bmp.height, true, 0x00000000);
  5. clone.draw(bmp.bitmapData);
  6.  
  7. // make color values lower than treshold transparent
  8. clone.threshold(clone, new Rectangle(0, 0, bmp.width, bmp.height), new Point(0,0), "<", treshold, 0);
  9.  
  10. return clone.getColorBoundsRect(0xFFFFFFFF, 0x00000000, false);
  11. }

Report this snippet  

You need to login to post a comment.