HTML5 : camera access

标签 html camera native

我是 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/

相关文章:

javascript - 通过 iframe 调用时,XML 被解析为 HTML

javascript - 基本 JS/HTML5 Canvas 问题

javascript - 如何从已编译的 Electron 应用程序中获取源文件?

java - LibGDX : How to retrieve a picture that was taken through the camera and saved locally?

camera - 如何使用网络摄像机集成人脸和物体识别?

android - 在后台运行 native 代码

javascript - 为什么我的模式不起作用? Bootstrap4

c# - 没有相机的 FileOpenPicker

c - jni - 将 int[][] 转换为 jobjectArray 并将其返回给 java

android - javah 找不到 android 类