WebCam捕获图像

时间:2013-01-15 00:37:30

标签: jquery html webcam

我正在尝试使用Jquery WebCam Plugin从我的网络摄像头捕获图像。我无法看到捕获的图像。我想我的代码中缺少一些东西。我需要捕获图像并在画布中将其显示给用户。

CODE:

$(document).ready(function(){


    $("#camera").webcam({
            width: 315,
            height: 240,
            useMicrophone: false,
            mode: "callback",
            swffile: "resources/swf/jscam_canvas_only.swf", 


            onLoad: function() {

                var cams = webcam.getCameraList();
                for(var i in cams) {
                    jQuery("#cams").append("<li>" + cams[i] + "</li>");
                }
            },

            debug: function (type, string) {
                $("#status").html(type + ": " + string);
            },

            onCapture: function () {

                jQuery("#flash").css("display", "block");
                jQuery("#flash").fadeOut("fast", function () {
                jQuery("#flash").css("opacity", 1);

                webcam.capture();
                 alert($.webcam.getFrameAsBase64());    
                });


            },

            onSave: function(data) {

                var col = data.split(";");
                var img = image;

                for(var i = 0; i < 320; i++) {
                    var tmp = parseInt(col[i]);
                    img.data[pos + 0] = (tmp >> 16) & 0xff;
                    img.data[pos + 1] = (tmp >> 8) & 0xff;
                    img.data[pos + 2] = tmp & 0xff;
                    img.data[pos + 3] = 0xff;
                    pos+= 4;
                }

                if (pos >= 4 * 320 * 240) {
                    ctx.putImageData(img, 0, 0);
                    pos = 0;
                }
            }





    }); 

});

<label id="status"></label>                             
                    <div id="camera"></div>
                    <div><p><canvas id="canvas" height="240" width="320"></canvas></p></div>
                     <a href="javascript:webcam.capture();changeFilter();void(0);">Take a picture instantly</a>

0 个答案:

没有答案