| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418 |
- // 高拍仪操作对象
- var Capturer = function() {
- };
- (function() {
- Capturer.prototype = {
- construct : Capturer,
- // 私有属性
- _parameter : {
- 'domId' : null, // 控件容器ID
- 'locationPath' : null, // 拍摄文件的本地存储路径
- 'produceFilenameFunc' : null, // 生成拍摄文件名称的函数体
- 'filename' : null, // 拍摄文件名称
- 'capturerCtrl' : null, // 高拍仪底层控制驱动
- 'iDeviceIndex' : null, // 高拍仪的摄像头编号
- 'postfix' : '.jpg', // 生成文件的格式
- 'strFileNames' : new Array(), // 双摄像头模式下,存放三张图片全路径的数组
- 'strMergeSource1' : null, // 合并图像的源文件1
- 'strMergeSource2' : null, // 合并图像的源文件2
- 'srcFileFullPathArr' : new Array(), // 存放本次业务所拍摄的所有文档全路径的数组
- 'fso' : new ActiveXObject('Scripting.FileSystemObject'), // JS文件操作对象
- 'capturerCtrlInitHtml' : '<%-- ActiveX控件对象 --%>'
- + '<object id="capturerCtrl" class="capturerCtrl" style="width: 100%;height: 100%;" '
- + 'classid="clsid:9A73DB73-2CA3-478D-9A3F-7E9D6A8D327C" codebase="/web/jsp/shoudan/capturer/CaptureVideo.CAB#V1,1,1,4"></object>'
- },
- getParameter : function(key) {
- return this._parameter[key];
- },
- setParameter : function(key, value) {
- this._parameter[key] = value;
- },
- /**
- * 【扫描】接口方法
- * @introduction 该方法用于调用高拍仪拍摄文档
- * @return flag {boolean} true=拍摄成功 false=拍摄失败
- */
- scan : function() {
- if( 0 == this._getDeviceState()){ //设备处于正常状态
- // 执行该函数,获得本次扫描的文件名称
- var filename = this._executeFunc(this.getParameter("produceFilenameFunc"));
- this.setParameter("filename", filename);
- var flag = this._captureToFile();
- return flag;
- }else{ // 设备处于异常状态
- alert("设备处于异常状态!");
- }
- },
- /**
- * 【重新扫描】接口方法
- * @introduction 重新扫描,删除已拍摄的文件,再次调用拍摄
- * @return flag {boolean} true=拍摄成功 false=拍摄失败
- */
- rescan : function() {
- this._deleteLocalTempFile();
- var flag = this.scan(); //删除所有图像后徐重新再获取一张当前的界面图片
- return flag;
- },
-
- /**
- * 【切换镜头】接口方法
- * @introduction 切换镜头,方法可以切换文档摄像头和人性摄像头。 {int} 0=文档摄像头 1=人像摄像头
- */
- switchCamera : function() {
- this._closeDevice();
- var iDeviceIndex = this.getParameter('iDeviceIndex');
- this._changeColorType(0); // 设置拍摄图片的颜色:彩色
- if(0 == iDeviceIndex){ // 文档摄像头
- iDeviceIndex = 1; // 修改为“人像摄像头”
- this._openDevice(iDeviceIndex);
- this._changePersonCameraDpi(3);
- }else{ // 人像摄像头
- iDeviceIndex = 0; // 修改为“文档摄像头”
- this._openDevice(iDeviceIndex);
- this._changeDocumentCameraDpi(0);
-
- }
- },
- /**
- * 【获取文件路径】接口方法
- * @introduction 获取扫描文件在本地上的储存路径的数组
- * @return String[] 返回扫描文件在本地上的储存路径的数组
- */
- getFilePath : function() {
- return this.getParameter("srcFileFullPathArr");
- },
-
- /**
- * 【旋转镜头】接口方法
- * @introduction 依次对高拍仪的镜头进行旋转
- */
- rotateCamera : function(){
- this._setDeviceRotation(90);
- },
- /**
- * 【设备状态初始化】公用方法
- * @introduction 进入页面时触发的初始化动作
- */
- initialization : function() {
- this.setParameter("capturerCtrl", capturerCtrl);
- this._changeColorType(0); // 设置拍摄图片的颜色:彩色
- this._openDevice(0);
- },
-
- /**
- * 【设备状态反初始化】公用方法
- * @introduction 离开页面是触发的反初始化动作
- */
- deinitialization : function() {
- this._closeDevice();
- this._deleteLocalTempFile();//删除所有的本地临时文件
- },
- /**
- * 【打开设备】私有方法
- *
- * @param value=设备的编号(0=文档摄像头,1=人像摄像头,2=双摄像头}
- */
- _openDevice : function(value) {
- iDeviceIndex = parseInt(value); // 选择待启动的设备
- if(0 != capturerCtrl.GetDeviceState(iDeviceIndex)){ // 若设备异常关闭,首次进来时先关闭后再打开
- capturerCtrl.CloseDeviceEx();
- }
- this.setParameter('iDeviceIndex',iDeviceIndex); // 设置当前的摄像头
- if (capturerCtrl.OpenDevice(iDeviceIndex) == 0) {
- capturerCtrl.SetCameraExposure(iDeviceIndex, 10); // 设置自动曝光
- }
- },
- /**
- * 【关闭设备】私有方法
- */
- _closeDevice : function() {
- capturerCtrl.CloseDeviceEx();
- },
- /**
- * 【拍照并且存档】私有方法
- * @return flag {boolean} true=拍摄成功 false=拍摄失败
- */
- _captureToFile : function() {
- // 获取strFileNames数组对象用于存放“操作后”的图片的全路径
- var strFileNames = this.getParameter("strFileNames");
- // 新建一个strFileName数组对象用于存放”操作前“的图片全路径
- var strFileNameArr = new Array();
- // 所有拍摄后的图片都要放在数组,即该数组存放本次业务的所有扫描件路径
- var srcFileFullPathArr = this.getParameter("srcFileFullPathArr");
- var result = false; // 拍摄是否成功结果,默认为false
-
- if (iDeviceIndex != 2) {// 文档摄像头或人像摄像头
- // 扫描文档
- var strFileName = this.getParameter("locationPath")
- + this.getParameter("filename")
- + this.getParameter("postfix");
- // 拍摄图片
- result = capturerCtrl.GrabToFile(strFileName);
- strFileNameArr.push(strFileName);
- // 所有的扫描件的全路径都要记录在这个数组中
- srcFileFullPathArr.push(strFileName);
- } else { // 双摄像头模式[暂时废弃不用,没有做预览功能]
- // 数组第”1“个元素放置的是”两个摄像头组合而成“的图片
- strFileNameArr[0] = this.getParameter("locationPath")
- + this.getParameter("filename") + "-Combined"
- + this.getParameter("postfix"); // 组合摄像
- var strDocFileName = this.getParameter("locationPath")
- + this.getParameter("filename") + "-SplitedDoc"
- + this.getParameter("postfix"); // 文档摄像
- var strPerFileName = this.getParameter("locationPath")
- + this.getParameter("filename") + "-SplitedPer"
- + this.getParameter("postfix"); // 人像摄像
- // 数组第”2“个元素放置的是”两个摄像头分别拍摄的“的图片
- strFileNameArr[1] = strDocFileName + ";" + strPerFileName;
- for ( var index = 0; index < 2; index++) {
- if (capturerCtrl.GrabToFile(strFileNameArr[index]) == 0) {// 拍摄成功
- if (index == 0) {
- capturerCtrl.ImagesToMultiPageFile(
- strFileNameArr[index], 0);
- strFileNames.push(strFileNameArr[index]);
- // 只保存最后2次拍摄的文件名作为合并图像参数文件名
- //strMergeSource1 = strMergeSource2;
- //strMergeSource2 = strFileName[index];
- } else {
- capturerCtrl.ImagesToMultiPageFile(strDocFileName,
- 0);
- capturerCtrl.ImagesToMultiPageFile(strPerFileName,
- 0);
- strFileNames.push(strDocFileName);
- strFileNames.push(strPerFileName);
- // 摄像头拍摄模式下,保存最后2次拍摄的文件名(两个摄像头分别拍摄的文件)作为合并图像参数文件名
- this.setParameter("strMergeSource1", strDocFileName);
- this.setParameter("strMergeSource2", strPerFileName);
- }
- }
- }
- }
- var flag = this._changeResultFlag(result);
- return flag;
-
- },
- /**
- * 【摄像旋转】私有方法
- *
- * @param rotation=旋转角度
- */
- _setDeviceRotation : function(rotation) {
- var rotationScope = parseInt(rotation);
- if (rotationScope % 90 != 0) {
- capturerCtrl.SetDeviceRotate(iDeviceIndex, 0); // 不能被90整除的默认不旋转
- }
- capturerCtrl.SetDeviceRotate(iDeviceIndex, rotationScope);
- },
- /**
- * 【判断内容是否为数字】私有方法
- *
- * @param value=校验的内容
- */
- _isDigit : function(value) {
- var patrn = /^-?\d+(\.\d+)?$/;
- if (!patrn.exec(value)) {
- return false
- }
- return true;
- },
- /**
- * 【自动对焦(只对自动对焦的高拍仪有效)】私有方法
- */
- _triggerAutoFocuse : function() {
- capturerCtrl.TriggerAutoFocuse();
- },
- /**
- * 【去除阴影】私有方法
- */
- _reduceShadow : function() {
- if (checkReduceShadow.checked) {
- capturerCtrl.ReduceShadow(0);
- } else {
- capturerCtrl.ReduceShadow(1);
- }
- },
- /**
- * 【文档形变修补功能】私有方法
- */
- _repairDistortion : function() {
- if (checkRepairDistortion.checked) {
- capturerCtrl.RepairDistortion(0);
- } else {
- capturerCtrl.RepairDistortion(1);
- }
- },
- /**
- * 【连续拍摄】私有方法,暂时没用,故未完善
- */
- _startContinuousShooting : function() {
- var strFileName = "D:\\DocImage";
- capturerCtrl.StartContinuous(strFileName, 0);
- },
- /**
- * 【拍摄界面缩放】私有方法
- *
- * @param value=(0=缩小,1=放大)
- */
- _zoomVideo : function(value) {
- var iZoomType = parseInt(value);
- capturerCtrl.ZoomInOut(iZoomType);
- },
- /**
- * 【设置拍照存档的DPI】私有方法
- *
- * @param dpiValue=待设置的dpi值
- */
- _setDPI : function(dpiValue) {
- if (dpiValue == "") {
- alert("DPI值都不能为空!");
- return;
- }
- if (this._isDigit(dpiValue)) {
- iDpi = parseInt(dpiValue);
- capturerCtrl.SetGrabbedDPIEx(iDpi);
- } else {
- alert("含有非法字符,请重新输入数字!");
- }
- },
-
- /**
- * 【获取设备状态】私有方法
- * @return 返回设备状态的代号
- */
- _getDeviceState : function() {
- //alert(capturerCtrl.GetDeviceState(iDeviceIndex));
- switch (capturerCtrl.GetDeviceState(iDeviceIndex)) {
- case -1: {
- return -1;
- }
- case 0: {
- return 0;
- }
- case 1: {
- return 1;
- }
- case 2: {
- return 2;
- }
- default: {
- break;
- }
- }
- },
-
- /**
- * 【执行入参方法】私有方法
- * @param value=入参为一个方法结构体
- */
- _executeFunc : function(value) {
- var produceFilenameFunc = value;
- return produceFilenameFunc();
- },
- /**
- * 【JS删除文件操作】私有方法
- * @param fileFullPath=文件的全路径
- */
- _deleteFile : function(fileFullPath) {
- var fso = this.getParameter("fso");
- if (fso.FileExists(fileFullPath)) {
- fso.DeleteFile(fileFullPath);
- }
- },
-
- /**
- * 【删除所有本地所有的扫描文件】私有方法
- */
- _deleteLocalTempFile : function(){
- var srcFileFullPathArr = this.getParameter("srcFileFullPathArr");
- for(var index = 0; index < srcFileFullPathArr.length; index++){
- this._deleteFile(srcFileFullPathArr[index]);
- this.setParameter("srcFileFullPathArr", []); // 本次业务存放扫描件的数据也要对应清空
- }
- },
-
- /**
- * 【改变拍摄结果返回值方法】私有方法
- * @introduction 由于高拍仪返回结果是数字代码,0表示的是成功,其它数字表示其它错误
- * @return flag {boolean} true=拍摄成功 false=拍摄失败
- */
- _changeResultFlag : function(resultFlag){
- return resultFlag == 0 ? true : false;
- },
-
- /**
- * 【改变拍摄图片颜色】私有方法
- * @param colorType {int} 0=彩色 1=灰度
- */
- _changeColorType : function(colorType){
- capturerCtrl.SetColorMode(colorType);
- },
-
- /**
- * 【改变文档摄像头的分辨率】私有方法
- * @param value {int}
- * 0 = 2592*1944
- * 1 = 1280*960
- * 2 = 1920*1080
- * 3 = 1600*1200
- * 4 = 2048*1536
- */
- _changeDocumentCameraDpi : function(value){
- var iIndex = parseInt(value);
- var iW = capturerCtrl.GetResolutionWidth(iDeviceIndex, iIndex);
- var iH = capturerCtrl.GetResolutionHeight(iDeviceIndex, iIndex);
- //console.log(iW + "*" + iH );
- var test = capturerCtrl.SetResolutionByWH(this.getParameter("iDeviceIndex"), iW, iH);
- },
-
- /**
- * 【改变人像摄像头的分辨率】私有方法
- * @param value {int}
- * 0 = 640*480
- * 1 = 800*600
- * 2 = 1280*720
- * 3 = 1280*960
- * 4 = 1600*1200
- * 5 = 320*240
- */
- _changePersonCameraDpi : function(value){
- var iIndex = parseInt(value);
- var iW = capturerCtrl.GetResolutionWidth(iDeviceIndex, iIndex);
- var iH = capturerCtrl.GetResolutionHeight(iDeviceIndex, iIndex);
- //console.log(iW + "*" + iH );
- var test = capturerCtrl.SetResolutionByWH(this.getParameter("iDeviceIndex"), iW, iH);
- }
-
- };
- // 扫描仪操作对象设置并初始化
- Capturer.config = function(initParam) {
- var capturer = new Capturer();
- capturer.setParameter('domId', initParam['domId']);
- capturer.setParameter('locationPath', initParam['locationPath']);
- capturer.setParameter('produceFilenameFunc', initParam['produceFilenameFunc']);
- $('#' + capturer.getParameter('domId')).html(
- capturer.getParameter('capturerCtrlInitHtml'));
- return capturer;
- };
- })();
|