lyp13140
筱雅的未来
2016-04-05 08:39

求助大神~网页中调用摄像头左右方向反了额,用拍照软件试了,摄像头本身没问题,下面是代码

 <!DOCTYPE HTML >
<html>
  <head>
    <title>cam.html</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
   <video id="video" autoplay=""style='width:600px;height:400px'></video>
   <button id='picture'>拍照</button> 
   <canvas id="canvas" width="600" height="400"></canvas>
   <script type="text/javascript">
   var video = document.getElementById("video");
   var context = canvas.getContext("2d")
   var errocb = function () {
                             console.log('sth wrong!');
                        }
   if (navigator.getUserMedia) { // 标准的API
       navigator.getUserMedia({ "video": true }, function (stream) {
           video.src = stream;
           video.play();
       }, errocb);
} else if (navigator.webkitGetUserMedia) { // WebKit 核心的API
       navigator.webkitGetUserMedia({ "video": true }, function (stream) {
           video.src = window.webkitURL.createObjectURL(stream);
           video.play();
       }, errocb);
}
   document.getElementById("picture").addEventListener("click", function () {
       context.drawImage(video, 0, 0, 600, 400);
});

     </script>
  </body>
</html>

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答