Skip to content

Instantly share code, notes, and snippets.

@lynxerzhang
Last active October 11, 2015 10:28
Show Gist options
  • Save lynxerzhang/3845323 to your computer and use it in GitHub Desktop.
Save lynxerzhang/3845323 to your computer and use it in GitHub Desktop.
get displayObject's bitmap copy(filters, colorTransform)
function getActualBitmapData(dis:DisplayObject):Sprite{
//TODO, the dis must be on the stage
var realBounds:Rectangle = dis.getBounds(dis.parent);
var c:ColorTransform = dis.transform.colorTransform;
var b:Rectangle = new Rectangle(0, 0, realBounds.width, realBounds.height);
var mt:Matrix = dis.transform.matrix;
var len:int = dis.filters.length;
if(len > 0){
for(var i:int = 0; i < len; i ++){
var temp:BitmapData = new BitmapData(realBounds.width, realBounds.height, true, 0);
var tempRect:Rectangle = temp.generateFilterRect(temp.rect, dis.filters[i]);
b = b.union(tempRect);
temp.dispose();
}
}
b.offset(realBounds.x, realBounds.y);
mt.translate(-b.x, -b.y);
var d:BitmapData = new BitmapData(b.width, b.height, true, 0);
d.draw(dis, mt, c);
var s:Sprite = new Sprite();
var bp:Bitmap = new Bitmap(d);
s.addChild(bp);
bp.x = -mt.tx;
bp.y = -mt.ty;
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment