Flex操作摄像头
Flex通过Camera类来操作摄像头。使用Camera类可以通过连接运行Adobe Flash Player的计算机的视频摄像头捕获视频。
Camera类通过getCamera()方法返回摄像头,在WSF访问摄像头时,Flash Player会显示一个对话框,用户可以通过该对话框允许或拒绝对摄像头的访问。
简单示例:
1: <?xml version="1.0" encoding="utf-8"?>
2: <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="InitCamera()">
3: <mx:Script>
4: <![CDATA[
5: import flash.events.*;
6: import flash.media.Camera;
7: import flash.media.Video;
8:
9: private var video:Video;
10: public function InitCamera():void
11: {
12: //获取摄像头
13: var c:Camera=Camera.getCamera();
14: if(c != null)
15: {
16: c.addEventListener(ActivityEvent.ACTIVITY,activityHandler);
17: video=new Video(c.width*2,c.height*2);
18: video.attachCamera(c);
19: vdTest.addChild(video);
20: }
21: else
22: {
23: trace("请连接摄像头");
24: }
25: }
26:
27: private function activityHandler(event:ActivityEvent):void{
28: trace("activityHandler: " + event);
29: }
30:
31: ]]>
32: </mx:Script>
33:
34: <mx:VideoDisplay id="vdTest" width="160" height="120"/>
35: </mx:Application>