Return to Snippet

Revision: 58868
at August 7, 2012 19:27 by tinytiger


Initial Code
private function trimTransparency(bmp:Bitmap, treshold:uint = 0xFF333333):Rectangle {
	
  // Clone the orignal with a clear background
  var clone:BitmapData = new BitmapData(bmp.width, bmp.height, true, 0x00000000);
  clone.draw(bmp.bitmapData);
		
  // make color values lower than treshold transparent
  clone.threshold(clone, new Rectangle(0, 0, bmp.width, bmp.height), new Point(0,0), "<", treshold, 0);
	   
  return clone.getColorBoundsRect(0xFFFFFFFF, 0x00000000, false);
}

Initial URL


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

Initial Title
Return trimmed bounding box of bitmap

Initial Tags
flash

Initial Language
ActionScript 3