var pos = 0, ctx = null, saveCB, image =[];var w=320;var h=240;var canvas = document.createElement("canvas");
canvas.setAttribute('width', w);
canvas.setAttribute('height', h);if (1==0&&canvas.toDataURL) {//支持HTML5时候用
debugger;
ctx= canvas.getContext("2d");
image= ctx.getImageData(0, 0, w, h);
saveCB= function(data) {//会循环调用该方法直到读完每行,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 * w *h) {
ctx.putImageData(img,0, 0);
$.ajax({
url :"../test2/video",
dataType :"json",
type :'post',
data:{
type:"data",
image: canvas.toDataURL("image/png")
},
error:function(e)
{
},
beforeSend:function(){
layer.load();
},
complete:function(){
layer.closeAll('loading');
},
success :function(url) {
$('#myImg').attr('src',url);
}
})//$.post("../test2/video?tmp=" + Math.random(), {type: "data", image: canvas.toDataURL("image/png")},function(url)
//{
//$('#myImg').attr('src',url);
//},"json");
pos = 0;
}
};
}else{
saveCB= function(data) {//循环调用该方法
image.push(data);
pos+= 4 *w;if (pos >= 4 * w *h) {
$.ajax({
url :"../test2/video",
dataType :"json",
type :'post',
data:{
type:"pixel",
image: image.join('|'),
w:w,
h:h
},
error:function(c)
{
},
beforeSend:function(){
layer.load();
},
complete:function(){
layer.closeAll('loading');
},
success :function(url) {
$('#myImg').attr('src',url);
}
})//$.post("../test2/video", {type: "pixel", image: image.join('|'),w:w,h:h},function(url)
//{
//alert(url);
//$('#myImg').attr('src',url);
//},"json");
pos = 0;
}
};
}
$("#webcam").webcam({
width: w,
height: h,
mode:"callback",
swffile: swfpah,
onSave: saveCB,
onCapture:function() {
webcam.save();
},
debug:function(type, string) {
console.log(type+ ": " +string);
},
onLoad:function() {
$('#test').bind('click',function(){
webcam.capture();
});
}
});
});