gpt4 book ai didi

HTML5 : camera access

转载 作者:技术小花猫 更新时间:2023-10-29 11:38:48 25 4
gpt4 key购买 nike

我是 HTML5 的新手。我尝试使用以下 HTML5 代码来访问我手机上的相机。它始终显示“不支持 native 网络摄像头”。看来我的手机浏览器(safari 和 android 2.1 网络浏览器)不支持相机。

您能告诉我应该使用哪个浏览器访问相机吗?

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, maximum-scale=1.0">
<style>
body {width: 100%;}
canvas {display: none;}
</style>
<script>
var video, canvas, msg;
var load = function () {
video = document.getElementById('video');
canvas = document.getElementById('canvas');
msg = document.getElementById('error');
if( navigator.getUserMedia ) {
video.onclick = function () {
var context = canvas.getContext("2d");
context.drawImage(video, 0, 0, 240, 320);
var image = {"demo" : {
"type" : "device",
"image" : canvas.toDataURL("image/png")
}};
};

var success = function ( stream ) {
video.src = stream;
};

var error = function ( err ) {
msg.innerHTML = "Error: " + err.code;
};

navigator.getUserMedia('video', success, error);

} else {
msg.innerHTML = "Native web camera not supported :(";
}

};

window.addEventListener('DOMContentLoaded', load, false);
</script>
</head>
<body>
<video id="video" width="240" height="320" autoplay> </video>
<p id="error">Click on the video to send a snapshot to the receiving screen</p>
<canvas id="canvas" width="240" height="320"> </canvas>
</body>
</html>

最佳答案

Firefox 17+、Chrome 23+ 和 Opera 12+ 现在支持 getUserMedia 方法。 (参见 caniuse.com)

Screenshot of the CanIUse.com support grid as of 2/24/12

关于HTML5 : camera access,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9431475/

25 4 0
文章推荐: html - 嵌套

行不通,而嵌套

Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com