Barring finding a method to do this, I hacked together a solution.
First, I found the bounds of all transparent pixels using getColorBoundsRect.
Next I iterated from the top-down until I found the first line with only
transparent pixels to revise the top edge
Finally I iterated from the bottom-up until finding the bottom line of only
transparent pixels to revise the bottom edge.
I was able to compensate like as such because I know that the rectangle is not
impeded from the sides at any point, otherwise I would have had to find the
left and right edges as well.
I feel like there should be an easier way (and also a less processor-intensive
way) to do this.
var clBD:BitmapData = new BitmapData(735,600,true, 0x00FFFFFF);
clBD.draw(contentLoader.content);
var transparentRect:Rectangle =
clBD.getColorBoundsRect(0xFF000000,0x00000000,true);
var top:Number = transparentRect.y;
var bottom:Number = transparentRect.y + transparentRect.height;
for(var i:uint = transparentRect.y ; i < bottom ; i++){
for(var j:uint = transparentRect.x ; j < (transparentRect.x +
transparentRect.width - 1) ; j++){
if((clBD.getPixel32(j,i) >> 24 & 0xFF) > 50){
top++;
j = transparentRect.x + transparentRect.width;
}else if(j == (transparentRect.x + transparentRect.width - 2)){
i = bottom;
j = transparentRect.x + transparentRect.width;
}
}
}
for( i = (transparentRect.y + transparentRect.height) ; i > top ; i -- ){
for( j = transparentRect.x ; j < (transparentRect.x + transparentRect.width
- 1) ; j++){
if((clBD.getPixel32(j,i) >> 24 & 0xFF) > 10){
bottom -- ;
j = transparentRect.x + transparentRect.width;
}else if(j == (transparentRect.x + transparentRect.width - 2)){
i = top;
j = transparentRect.x + transparentRect.width;
}
}
}
clBD.dispose();
Wow, 3 months and no-one can find a better way to do this?