我无法拍摄照片,但我可以在网络摄像头上看到自己。我不确定缺少什么。到目前为止,我的进展如下:
Jsp页面:
$(document).ready(function(){
$("#camera").webcam({
width: 315,
height: 240,
mode: "callback",
swffile: "swf/jscam_canvas_only.swf",
onLoad: function () {
var cams = webcam.getCameraList();
for(var i in cams) {
jQuery("#canvas").append("<li>" + cams[i] + "</li>");
}
jQuery("#canvas").hide();
},
onCapture: function () {
jQuery("#flash").css("display", "block");
jQuery("#flash").fadeOut(100, function () {
jQuery("#flash").css("opacity", 1);
});
jQuery("#canvas").show();
webcam.save();
},
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;
}
}
});
});
<div id="camera"></div><label>Canvas</label>
<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>