/ 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).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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); }