[AS3]摄像头录制
2007-7-30
看了AS2做的摄像头录制程序,挺简单的,就想用AS3做,练习一下,本以为很简单,没想到写了代码后错漏百出,好不容易都改正过来了,结果怎么调录制的图象跟原图象的尺寸都不一样,搞得我都不想再做了。先放上来,高手知道的说下啊~
AS文件代码:
package{
import flash.display.Sprite
import flash.media.Camera
import flash.events.MouseEvent
import flash.display.BitmapData
import flash.events.Event
import flash.media.Video
import flash.display.Bitmap
public class camera extends Sprite{
var mycamera:Camera=Camera.getCamera()
var myvideo:Video=new Video()
var bit:Array
var vwidth=250
var vheight=200
var i:uint=1
var playvideo:Bitmap=new Bitmap()
public function camera (){
myvideo.attachCamera(mycamera)
myvideo.smoothing=true
myvideo.width=vwidth
myvideo.height=vheight
myvideo.x=50
myvideo.y=30
addChild(myvideo)
addChild(playvideo)
}
public function rec_btn(btn){
btn.addEventListener(MouseEvent.MOUSE_DOWN,on_rec_btn)
}
public function play_btn(btn){
btn.addEventListener(MouseEvent.MOUSE_DOWN,on_play_btn)
}
public function stop_btn(btn){
btn.addEventListener(MouseEvent.MOUSE_DOWN,on_stop_btn)
}
public function on_rec_btn(event:MouseEvent){
bit=new Array()
i=1
addEventListener(Event.ENTER_FRAME,onenterframe)
}
public function on_stop_btn(event:MouseEvent){
removeEventListener(Event.ENTER_FRAME,onenterframe)
removeEventListener(Event.ENTER_FRAME,onenterframeplay)}
public function on_play_btn(event:MouseEvent){
addEventListener(Event.ENTER_FRAME,onenterframeplay)
}
private function onenterframe(event:Event){
var rec:BitmapData=new BitmapData(vwidth,vheight,true,0xff)
rec.draw(myvideo)
bit.push(rec)
}
private function onenterframeplay(event:Event){
if(i<bit.length){
playvideo=new Bitmap(bit[i])
playvideo.x=360
playvideo.y=30
addChild(playvideo)
i++
}else{
removeEventListener(Event.ENTER_FRAME,onenterframeplay)
}}
}
}
本机录制时间不能太长否则就会卡主。