• Web调取摄像头拍照


    调取摄像头、拍照

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title></title>
    </head>
    <body>
    <video width="640" height="480" id="myVideo"></video>
    <canvas width="640" height="480" id="myCanvas"></canvas>
    <button id="myButton">拍摄</button>
    <button id="myButton2">预览</button>
    <button id="myButton3">
    <a download="video.png">另存为</a>
    </button>
    </body>
    </html>

    js 调用

    <script>
    window.addEventListener('DOMContentLoaded',function(){
    var cobj=document.getElementById('myCanvas').getContext('2d');
    var vobj=document.getElementById('myVideo');
    getUserMedia({video:true},function(stream){
    vobj.src=stream;
    vobj.play();
    },function(){});
    document.getElementById('myButton').addEventListener('click',function(){
    cobj.drawImage(vobj,0,0,640,480);
    document.getElementById('myButton3').children[0].href=cobj.canvas.toDataURL("image/png");
    },false);
    document.getElementById('myButton2').addEventListener('click',function(){
    window.open(cobj.canvas.toDataURL("image/png"),'_blank');
    },false);
    },false);
    function getUserMedia(obj,success,error){
    if(navigator.getUserMedia){
    getUserMedia=function(obj,success,error){
    navigator.getUserMedia(obj,function(stream){
    success(stream);
    },error);
    }
    }else if(navigator.webkitGetUserMedia){
    getUserMedia=function(obj,success,error){
    navigator.webkitGetUserMedia(obj,function(stream){
    var _URL=window.URL || window.webkitURL;
    success(_URL.createObjectURL(stream));
    },error);
    }
    }else if(navigator.mozGetUserMedia){
    getUserMedia=function(obj,success,error){
    navigator.mozGetUserMedia(obj,function(stream){
    success(window.URL.createObjectURL(stream));
    },error);
    }
    }else{
    return false;
    }
    return getUserMedia(obj,success,error);
    }
    </script>
  • 相关阅读:
    嵌入式整体框架——总结
    DSP Bios记忆
    三遥
    usb设备 配置 接口 端点
    ARM, MIPS, Power PC的比较
    STM32 IAP
    FSMC 总结
    BCD码与十进制的相互转换
    读 “cortexM3” 权威指南 小记(一)
    crc校验码的16 32位 查表法 算法记载
  • 原文地址:https://www.cnblogs.com/dongh/p/6612082.html
Copyright © 2020-2023  润新知