zoukankan      html  css  js  c++  java
  • as3代码实现调用摄像头

    package {
        import flash.display.Sprite;
        import flash.media.Camera;
        import flash.media.Video;
        import flash.text.TextField;
        import flash.text.TextFieldAutoSize;
        import flash.utils.Timer;
        import flash.events.TimerEvent;
        import flash.events.ActivityEvent;
    
        public class main extends Sprite {
            private var myTextField:TextField;
            private var cam:Camera;
            private var t:Timer = new Timer(1000);
    
            public function main() {
                myTextField = new TextField();
                myTextField.background = true;
                myTextField.selectable = false;
                myTextField.autoSize = TextFieldAutoSize.LEFT;    
            
                cam = Camera.getCamera();
                
                if (!cam) {
                    myTextField.text = "No camera is installed.";
    
                }else {
                    myTextField.text = "Waiting to connect.";
                    connectCamera(); 
                }
    
                addChild(myTextField);
    
                t.addEventListener(TimerEvent.TIMER, timerHandler);
            }
    
            private function connectCamera():void {
                    var vid:Video = new Video(cam.width, cam.height);
                    vid.x = 10;
                    vid.y = 10;
                    vid.attachCamera(cam);
                    addChild(vid);    
    
                    cam.setMotionLevel(5, 1000);
                    cam.addEventListener(ActivityEvent.ACTIVITY, activityHandler);
            }
    
            private function activityHandler(e:ActivityEvent):void {
                if (e.activating == true) {
                    t.start();    
                } else {
                    myTextField.text = "Everything is quiet.";
                    t.stop();
                }    
            }
    
            private function timerHandler(event:TimerEvent):void {
                 myTextField.x = 10;
                 myTextField.y = cam.height + 20;
                 myTextField.text = "There is some activity. Level: " + cam.activityLevel;
            }
        }
    }
    

      

  • 相关阅读:
    数据库的操作封装成类
    简单搭建WEB框架及原理
    界面小项目之小米商品排列
    界面小项目之小米登录注册
    kubernetes版本1.7.6对比1.13.0
    docker将宿主机文件复制到容器内
    常用git命令
    centos7常用命令汇总
    openstack相关的命令总结
    kubernetes常用命令2
  • 原文地址:https://www.cnblogs.com/dt1991/p/14875631.html
Copyright © 2011-2022 走看看