我最终得出的解决方案是下面的,很可能不是最高效的方式,但它的工作原理。
/**
* Cuts off the transparency around a bitmap, returning the true width and height whilst retaining transparency
*
* @param input Bitmap
*
*/
private function trimTransparency(input:BitmapData,colourChecker:uint = 0x00FF00):Bitmap {
//Keep a copy of the original
var orignal:Bitmap = new Bitmap(input);
//Clone the orignal with a white background
var clone:BitmapData = new BitmapData(orignal.width, orignal.height,true,colourChecker);
clone.draw(orignal);
//Grab the bounds of the clone checking against white
var bounds:Rectangle = clone.getColorBoundsRect(colourChecker, colourChecker, false);
//Create a new bitmap to return the changed bitmap
var returnedBitmap:Bitmap = new Bitmap();
returnedBitmap.bitmapData = new BitmapData(bounds.width, bounds.height,true,0x00000000);
returnedBitmap.bitmapData.copyPixels(orignal.bitmapData,bounds, new Point(0,0));
return returnedBitmap;
}
有趣的问题 - 我想循环的两个方向是你最好的选择 – danjp 2010-10-22 16:27:04
是啊,我只是相信,我不能成为第一个需要双向透明度检查器的人。但是,如果没有,我会继续并发挥。 – karlfreeman 2010-10-22 16:35:56