• js摄像头


    
    <!DOCTYPE html>  
    <html lang="zh-CN">  
    <head>  
        <meta charset="UTF-8">  
        <title>GetUserMedia实例</title>  
    </head>  
    <body>  
            <!--  
            理想情况下我们应该先判断你的设备上是否  
            有摄像头或相机,但简单起见,我们在这里直接  
            写出了HTML标记,而不是用JavaScript先判断  
            然后动态生成这些标记  
        -->  
        <video id="video" width="640" height="480" style="border:solid 1px green" autoplay></video>  
        <button id="snap">Snap Photo</button>  
        <canvas id="canvas" width="640" height="480" style="border:solid 1px gray"></canvas>    
    </body>  
    <script type="text/javascript">  
      // Put event listeners into place  
    window.addEventListener("DOMContentLoaded", function() {  
        // Grab elements, create settings, etc.  
        var canvas = document.getElementById("canvas"),  
            context = canvas.getContext("2d"),  
            video = document.getElementById("video"),  
            videoObj = { "video": true },  
            errBack = function(error) {  
                console.log("Video capture error: ", error.code);   
            };  
      
        // Put video listeners into place  
        if(navigator.getUserMedia) { // Standard  
            navigator.getUserMedia(videoObj, function(stream) {  
                video.src = stream;  
                video.play();  
            }, errBack);  
        } else if(navigator.webkitGetUserMedia) { // WebKit-prefixed  
            navigator.webkitGetUserMedia(videoObj, function(stream){  
                video.src = window.webkitURL.createObjectURL(stream);  
                video.play();  
            }, errBack);  
        }  
        else if(navigator.mozGetUserMedia) { // Firefox-prefixed  
            navigator.mozGetUserMedia(videoObj, function(stream){  
                video.src = window.URL.createObjectURL(stream);  
                video.play();  
            }, errBack);  
        }
    
           document.getElementById("snap")  
           .addEventListener("click", function() {  
        context.drawImage(video, 0, 0, 640, 480);  
    }); 
    }, false);
    
    
    </script>  
    <html>
    
    
  • 相关阅读:
    软件工程课堂二
    软件工程第二周总结
    软件工程第一周开课博客
    软件工程课堂一
    开学第一次考试感想
    以Function构造函数方式声明函数
    document.scrollingElement
    标识符
    变量声明语句的提升
    用that代替this
  • 原文地址:https://www.cnblogs.com/humi/p/7268075.html
Copyright © 2020-2023  润新知