將顯示物件繪製為點陣圖資料
輔助函式,用於建立物件的點陣圖副本。這可用於將向量物件,文字或複雜的巢狀 Sprite 轉換為展平點陣圖。
function makeBitmapCopy(displayObj:IBitmapDrawable, transparent:Boolean = false, bgColor:uint = 0x00000000, smooth:Boolean = true):Bitmap {
//create an empty bitmap data that matches the width and height of the object you wish to draw
var bmd:BitmapData = new BitmapData(displayObj.width, displayObj.height, transparent, bgColor);
//draw the object to the bitmap data
bmd.draw(displayObj, null, null, null, null, smooth);
//assign that bitmap data to a bitmap object
var bmp:Bitmap = new Bitmap(bmd, "auto", smooth);
return bmp;
}
用法:
var txt:TextField = new TextField();
txt.text = "Hello There";
var bitmap:Bitmap = makeBitmapCopy(txt, true); //second param true to keep transparency
addChild(bitmap);