Return trimmed bounding box of bitmap

/ Published in: ActionScript 3
Save to your folder(s)

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).

Copy this code and paste it in your HTML
  1. private function trimTransparency(bmp:Bitmap, treshold:uint = 0xFF333333):Rectangle {
  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);
  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);
  10. return clone.getColorBoundsRect(0xFFFFFFFF, 0x00000000, false);
  11. }

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.