码迷,mamicode.com
首页 > Web开发 > 详细

html5调用摄像头

时间:2015-08-27 19:29:10      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

代码片段如下:

css部分代码:

video { border: 1px solid #ccc; display:inline-block; }
 #canvas { border: 1px solid #ccc; display:inline-block;}
 #take_photo{background-color:orange;width:100px;height:30px;border:0px;}

  html部分代码:

id="video" width="480" height="320" autoplay>
id="canvas" width="480" height="320">
id="take_photo" type="button" value="take_photo"/>
window.addEventListener("DOMContentLoaded", function() {
  var canvas = document.getElementByIdx_x("canvas"),
  context = canvas.getContext("2d"),
  video = document.getElementByIdx_x("video"),
  videoobj = {"video": true },
  errback = function(error) {
          console.log("error", error.code);
 };
  if(navigator.getUserMedia) {
            navigator.getUserMedia(videoobj, function( stream) {
                       video.src = stream;
                       video.play();
             }, errback);
  } else if (navigator.webkitGetUserMedia) {
                navigator.webkitGetUserMedia(videoobj,function(stream) {
                video.src = window.webkitURL.createObjectURL(stream);
                } , errback)
 }
  document.getElementByIdx_x("take_photo").addEventListener("click", function(){
         context.drawImage(video, 0, 0, 480, 320);
  });
}, false);



html5调用摄像头

标签:

原文地址:http://my.oschina.net/hxwny/blog/498201

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!