我正在使用jquery 网络摄像头插件,当我拍照时它没有出现在画布中。我想知道我是否必须先将图像上传到服务器才能显示在画布上,还是在拍摄后显示。
代码:
$(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.snap();
});
webcam.snap();
},
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>