rxbdscan.jsp 3.71 KB
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>

<title>shishi </title>
<meta name="decorator" content="default"/>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<script src="${ctxStatic}/jquery/jquery.webcam.min.js" type="text/javascript"></script>
<style type="text/css">
  div{
    text-align: center;
    vertical-align: middle;
  }
  
</style>
<script type="text/javascript">

$(function () {
	var ywh = "${ywh}";
	var sxh = "${sxh}";
	$.ajaxSetup({
		async:false
	});
	var pos = 0, ctx = null, saveCB,w = 320,h= 240, image = [];
    var canvas = document.createElement("canvas");//创建画布指定宽度和高度
    canvas.setAttribute('width', 600); 
    canvas.setAttribute('height', 450); 
	//如果画布成功创建
    if (canvas.toDataURL) {
        ctx = canvas.getContext("2d");//设置画布为2d,未来可能支持3d
        image = ctx.getImageData(0, 0, 320, 240);//截图320*240,即整个画布作为有效区(cutx?)
        saveCB = function(data) {
            var col = data.split(";");//把data切割为数组
            var img = image;
			//绘制图像(这里不是很理解算法)
			//参数 data  只是每行的数据  ,例如320*240 大小的照片,一张完整的照片下来需要240个data,每个data有320个rgb
            for(var i = 0; i < w; 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;
            }
			//当绘制320*240像素的图片时发给后端
            if (pos == 4 * w * h) {
				//把图像放到画布上,输出为png格式
                ctx.putImageData(img, 0, 0);
                $.post("${ctx}/reg/bus/uploadExamPic/uploadPic", {val: "data",w:w,h:h,ywh:ywh,sxh:sxh,image: canvas.toDataURL("image/png")},function(){
                });
                pos = 0;
            }
        };
    } else {
        saveCB = function(data) {
            image.push(data);//把数据一点点的放入image[]
            pos+= 4 * w;
            if (pos == 4 * w * h) {
                $.ajax({
					  type: 'POST',
					  url: "${ctx}/reg/bus/uploadExamPic/uploadPic",
					  data: {val: "pixel",w:w,h:h,ywh:ywh,sxh:sxh,image:image.join('|')},
					  success:function(){
						  pos = 0, ctx = null, saveCB,w = 320,h= 240, image = [];
					  }
				});
                pos = 0;
            }
        };
    }
	//拍照
    $("#webcam").webcam({
        width: 280,
        height: 240,
        mode: "callback",
        swffile: "${ctxStatic}/jquery/jscam_canvas_only.swf",//自己的路径
        onSave: saveCB,
        onCapture: function () {
        	$("#webcam").css("display", "block");
        	$("#webcam").fadeOut("fast", function () {
    		$("#webcam").css("opacity", 1);
    	});
            webcam.save();
        },
        debug: function (type, string) {
            console.log(type + ": " + string);
        }
    });
})

function savepho(){
	  webcam.capture();
	  losewin();
}

function losewin(){
	window.opener.location.reload();
	window.opener.reloadpicname();
	window.close();
} 

</script>
</head>
<body>
<label class="layui-form-label" style="width:60px;"><br/></label>
<div id="picView" style="width:296px;height:240px;margin-left:73px;">
<div id="webcam" style="width:286px;height:240px"></div>
</div >
<div>
      <br/><br/>
  <input type="button" id="button" value="拍照" onclick="savepho()"/>
</div>
<div style="display: none;">  
 </div>         
</body>

</html>