晚风

博客园 首页 新随笔 联系 订阅 管理

//最小矩形(非透明最小区域)  

public static function getMinRect(target:BitmapData):Rectangle{
   return target.getColorBoundsRect(0xffffffff,0x00000000,false);
  }

 

//去除多余透明区域
  public static function removeTransparentRect(target:BitmapData,minRect:Rectangle):BitmapData{   
   if(minRect.left==0 && minRect.top==0){
    return target;
   }
   var bytes:ByteArray=target.getPixels(minRect);
   var fillRect:Rectangle=new Rectangle(0,0,minRect.right-minRect.left, minRect.bottom-minRect.top);
   var resultBitmapData:BitmapData = new BitmapData(minRect.right-minRect.left, minRect.bottom-minRect.top,true,0);
   
   bytes.position=0;
   resultBitmapData.setPixels(fillRect,bytes);
   
   return resultBitmapData;
  }
posted on 2013-10-11 16:26  晚风  阅读(470)  评论(0编辑  收藏  举报