FLASH视频录制+抓图

stop();

实例名begin_btn,view_btn,norm_btn,photo_btn四个按钮,实例名为mybox的一个视频(库--新建视频),

//将按钮设为禁用
begin_btn.enabled = false;
view_btn.enabled = false;
norm_btn.enabled=false;

client_nc = new NetConnection();
client_nc.onStatus = function(info) {
// 利用trace功能将server返回的信息可视化
trace("Level: "+info.level+newline+"Code: "+info.code);
};
client_nc.connect("rtmp://192.168.0.10/chat");
//rec_so.connect(client_nc);
begin_btn.enabled = true;
view_btn.enabled = true;
norm_btn.enabled = false;

this.cam = Camera.get();
mybox.attachVideo(this.cam);
//this.cam.setMode(180, 140, 10, true);
out_ns = new NetStream(client_nc);
out_ns.attachVideo(this.cam);
begin_flag=true;
//开始/停止录象
begin_btn.onRelease = function() {
     if(begin_flag==true)
     {
   view_btn.enabled = false;
         norm_btn.enabled = false;
         out_ns.publish("烟头", "record");
   begin_btn.label="停止录象";
   begin_flag=false;
}
else
{
   begin_flag=true;
   begin_btn.label="开始录象";
   //停止在Video对象里面播放摄像头的图像
         mybox.attachVideo(null);
         out_ns.close();
   view_btn.enabled=true;
}
}

//观看录象
view_btn.onRelease = function() {
//view_btn.enabled=false
begin_btn.enabled=false;
norm_btn.enabled=true;
     //标签label的名称就是录像文件的名称
     var playFileName = "烟头";
     //创建新的NetStream流对象,将会用来播放留言信息
     in_ns = new NetStream(client_nc);
     //通过NetStream.play方法播放server上的flv文件
     in_ns.play(playFileName);
     //Video对象mybox作为视频流的播放载体,使媒体流可视化
     mybox.attachVideo(in_ns);
}
//正常
norm_btn.onRelease = function(){
this.cam = Camera.get();
mybox.attachVideo(this.cam);
out_ns.attachVideo(this.cam);
begin_btn.enabled = true;
view_btn.enabled = true;
norm_btn.enabled = true;
}

//拍照
photo_btn.onRelease=function()
{
//mybox.attachVideo(null);
myBitmap = new flash.display.BitmapData(160, 120, true, 0);
     myBitmap.draw(mybox);
     var tempObj = _root.createEmptyMovieClip("photo", 100);
     tempObj._x = 300;
     tempObj._y = 100;
       tempObj.attachBitmap(myBitmap, 1, "always", true);
for(i=0;i<160;i++)
{
      for(j=0;j<120;j++)
          trace(myBitmap.getPixel(i,j));//纪录每个像素的信息
}
}

你可能感兴趣的:(Flash)