HTML5:相机访问

lov*_*set 38 html5 camera native

我很新HTML5.我尝试使用以下HTML5代码访问手机上的相机.它始终显示"不支持本机网络摄像头".似乎我的移动浏览器(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>
Run Code Online (Sandbox Code Playgroud)

Ant*_*ull 40

getUserMediaFirefox 17 +,Chrome 23+和Opera 12+现在支持该方法.(见caniuse.com)

截至2012年2月24日的CanIUse.com支持网格的屏幕截图

  • @Anthony,问到有关在手机上访问相机的问题.Firefox 17 +,Chrome 23 +,Opera 12+在手机上不可用! (2认同)

Jez*_*z D 14

这适用于Firefox手机,Chrome手机,iPhone和Android:

<input type="file" id="mypic" accept="image/*">
Run Code Online (Sandbox Code Playgroud)


Dav*_*ter 5

通过网络拼凑的这种基本方法我们取得了一些成功:

<form method="post" action="takephoto.php" enctype="multipart/form-data">
<input type="file" accept="image/*" name="file">
<input type="submit">
</form>
Run Code Online (Sandbox Code Playgroud)

然后在PHP文件中,我们使用now()或类似的存储来生成唯一的文件名.


use*_*960 5

<input type="file" accept="image/*;capture=camera">
Run Code Online (Sandbox Code Playgroud)

请参阅HTML5中的捕获音频和视频

支持:

  • Android 3.0浏览器 - 首批实现之一.观看此视频,了解相关信息.
  • 适用于Android的Chrome(0.16)
  • Firefox Mobile 10.0
  • iOS6 Safari和Chrome(部分支持)


Rog*_*ger 3

我认为 Opera 是唯一支持此 HTML5 扩展的移动浏览器。

请参阅作者对此主题的注释;

http://francisshanahan.com/index.php/2011/stream-a-webcam-using-javascript-nodejs-android-opera-mobile-web-sockets-and-html5/