4

我正在使用画布捕获图像,我想使用 Javascript 将捕获的图像存储在 MySQL 数据库中。

这是我的代码:

<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>
            <title>Instant Camera - Remote</title>
            <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 image1 = canvas.toDataURL("image/png");
                    document.write('<img src="' + image1 + '" />');         
                        };

                    } 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>
4

1 回答 1

2

获取画布“屏幕截图”,将其编码为 BASE64 字符串,将其发送到 servlet/php/etc 并将其存储在 mysql 中应该可以工作。

于 2012-10-17T14:18:16.977 回答