Flash/Flex学习笔记(2):捕获摄像头
生活随笔
收集整理的這篇文章主要介紹了
Flash/Flex学习笔记(2):捕获摄像头
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Flash中使用攝像頭,個人感覺比silverlight要更容易
時間軸第一幀上敲以下代碼就可以了:
//import fl.controls.Label; //var camera:Camera = Camera.getCamera(); //trace(camera==null?"未檢測到攝像頭":"已安裝了攝像頭"); var W:int=stage.stageWidth;//場景的原始寬度 var H:int=stage.stageHeight;//場景的原始高度 stage.scaleMode=StageScaleMode.NO_SCALE;//舞臺禁止縮放,但是好象沒效果? var video:Video; var camera:Camera=Camera.getCamera(); if (camera==null) { trace("未檢測到攝像頭!"); lbl1.text="未檢測到攝像頭!"; btnCapture.visible=false; } else { camera.addEventListener(ActivityEvent.ACTIVITY,activityHander); video=new Video(camera.width,camera.height); trace("視頻寬度:" + camera.width + ",視頻高度:" + camera.height); video.attachCamera(camera); //定位到水平中心點 video.x = (W - video.width) /2; video.y=10; addChild(video);//加載到當前舞臺中 btnCapture.x = (W - btnCapture.width) /2; btnCapture.y=video.y+video.height+5; btnCapture.addEventListener(MouseEvent.CLICK,captureImage); } function activityHander(e:ActivityEvent):void { trace("activityHander:" + e); } var dp:DataProvider = new DataProvider(); function captureImage(e:MouseEvent):void { //trace("你點擊了按鈕"); var bit:BitmapData=new BitmapData(video.width,video.height); bit.draw(video); var bmp:Bitmap=new Bitmap(bit); //bmp.y=btnCapture.y+btnCapture.height+10; //bmp.x = (W - bmp.width) /2; var d:Date = new Date(); dp.addItem({label:"截圖" + d.getFullYear() + d.getMonth() + d.getDay() + d.getHours() + d.getMinutes() + d.getSeconds() + d.getMilliseconds(),source:bmp}); //addChild(bmp); tilelst1.dataProvider = dp; } stop();?
運行效果圖:
源代碼下載:http://cid-2959920b8267aaca.skydrive.live.com/self.aspx/Flash/GetCamera.rar
轉載于:https://www.cnblogs.com/happysky97/archive/2010/11/22/1884464.html
總結
以上是生活随笔為你收集整理的Flash/Flex学习笔记(2):捕获摄像头的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JavaScript类库
- 下一篇: 按功能顺序列出的 HTML 4.01/X