使用HTML5中的canvas和video技术实现调用PC摄像头
1.[代码][HTML]代码
HTML5调用电脑摄像头实例 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
//alert("支持navigator.getUserMedia");
navigator.getUserMedia(videoObj, function(stream) {
video.src = https://www.it610.com/article/stream;
video.play();
}, errBack);
} else if(navigator.webkitGetUserMedia) { // WebKit-prefixed
//alert("支持navigator.webkitGetUserMedia");
navigator.webkitGetUserMedia(videoObj, function(stream){
video.src = https://www.it610.com/article/window.webkitURL.createObjectURL(stream);
video.play();
}, errBack);
}
else if(navigator.mozGetUserMedia) { // Firefox-prefixed
//alert("支持navigator.mozGetUserMedia");
navigator.mozGetUserMedia(videoObj, function(stream){
video.src = https://www.it610.com/article/window.URL.createObjectURL(stream);
video.play();
}, errBack);
}
// 触发拍照动作
document.getElementById("snap").addEventListener("click", function() {
context.drawImage(video, 0, 0, 640, 480);
});
}, false);
【html|html 调用pc摄像头,HTML调用PC摄像头】点击拍照
推荐阅读
- 为什么下拉菜单在UIKit中不起作用()
- 主题更新后,header.php是否会在子主题中更新()
- html|HTML版扫雷
- 当你开始向下滚动时,顶部标题图像会抖动/抽搐,为什么( [关闭])
- 将WordPress更改为RTL时出现奇怪的空白
- 显示帖子缩略图而不是占位符placeholder
- html|CSS学习
- WEB前端|WEB前端进阶之路——CSS基础笔记 01
- WordPress博客中的Rogue&nbsp