如何将一个rect从movieclip复制到一个形状?

时间:2013-11-20 10:44:05

标签: actionscript-3

我想将一个区域从movieclip复制到形状图形,这可能吗?

另外,有什么建议的方法来清除bitmapdata?

1 个答案:

答案 0 :(得分: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对象的内存。