当前位置: > > > AS3 - 将Sprite元件转换成Bitmap图片

AS3 - 将Sprite元件转换成Bitmap图片

Flex/Flash开发中,有时会需要把组件转换成Bitmap格式的图片数据进行处理。调用如下方法即可:
public static function copySprite(obj:Sprite, tx:Number=0, ty:Number=0):Bitmap{
	var w:Number = obj.width;
	var h:Number = obj.height;
	if (((!((tx == 0))) || (!((ty == 0))))){
		w = tx;
		h = ty;
	};	
	var bmd:BitmapData = new BitmapData(w, h, true, 0);
	var matrix:Matrix = new Matrix();
	matrix.tx = 0;
	matrix.ty = 0;
	var bitmap:Bitmap = new Bitmap(bmd);
	bmd.draw(obj, matrix);
	return (bitmap);
} 
评论0