2013-11-20 108 views
0

我想的區域從影片剪輯複製到形狀的圖形,這可能嗎?如何從影片剪輯複製一個矩形的形狀?

此外,什麼是推薦的方式來清除位圖數據?

+0

你是什麼意思明確:),你是什麼意思一個區域:) –

+0

清除所有像素,並使其作爲新創建 – simo

回答

0

你可以試試這樣

//go to target frame 
    mc.gotoAndStop(1); 

    //the area you want to draw 
    var area:Rectange = new Rectange(50, 60, 100, 200); 

    if (mc.width != 0 && mc.height != 0) { 

     //draw the mc on the target frame 
     var temp:BitmapData = new BitmapData(mc.width, mc.height, true, 0x00000000); 
     temp.draw(mc); 

     //target area bitmapdata 
     var targetBD:BitmapData = new Bitmapdata(area.width, area.height, true, 0x00000000); 

     targetBD.copyPixels(temp, area, new Point(0, 0)); 

     //draw to shape 
     shape.graphics.beginBitmapFill(targetBD); 
     shape.graphics.drawRect(0, 0, area.width, area.height); 
     shape.graphics.endFill(); 
    } 

您可以撥打的BitmapData dispose方法來清洗的BitmapData,它會釋放用來存儲BitmapData對象的內存。

+0

dispose不會使它成爲新創建,但破壞它,並可能導致unnececerry垃圾收集 - 如果你需要重用「畫布」,你不妨使用'myBitmapData.fillRect(myBitmapData.rect,INIT_COLOR);'這裏INIT_COLOR與創建位圖或任何東西,當你想作爲背景使用使用的相同的帆布。 –

+0

@Lukasz我覺得他的明確意思是釋放內存,所以我建議他用處理功能。而我通常使用的BitmapData位圖,在大多數情況下使用BitmapData不會改變,所以才稱之爲bitmap.bitmapdata = NULL。 – Pan

相關問題