此为demo项目代码下载地址,以及捷宇的sdk
https://download.csdn.net/download/heqinghua217/10891291
百度网盘中放了ocx安装的exe文件(百度网盘中也包含了csdn中的附件)
https://pan.baidu.com/s/1fA7jeiqKd6ZdpNZHsKkngA
此demo主要用于测试高拍仪
高拍仪捷宇科技的, 版本是D系列
先安装驱动,以及捷宇自己的软件测试是否可以高拍,之后如果系统中ie界面需要高拍,那么需要安装《DoccameraOcx-ie运行的插件.zip》
安装完了之后,注册表会多一项内容 clsid:454C18E2-8B7D-43C6-8C17-B1825B49D7DE, 可以搜索454C18E2-8B7D-43C6-8C17-B1825B49D7DE 搜索的到
之后,就可以用index页面进行测试了。
ie注意得是大于等于ie8的版本,因为很多浏览器,你看他是ie8,或者ie10, f12调试模式可以看到,ie有两个模式
一个浏览器模式,一个文档模式,一般浏览器模式大家都是对的,文档模式有可能各不一样,有的是ie5,有的是ie6,要注意这点
上传功能需要引入lib中的三个jar,我的tomcat是6,jdk是1.7
(ps :其实重点是要学会如何根据sdk自己能会写出调用的方法来)
1、测试界面如下:
代码就不贴了,自己去看代码吧,就一个index.jsp,以及一个servlet,servlet主要用于上传附件,你们可以直接写一个,不需要参考,因为你们不可能是用servlet的,如果是struts,那么后台直接定义一个file ,然后getset之后就可以通过名称trackdata获取
2、servlet
package com.test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.time.DateFormatUtils;
public class UploadServlet extends HttpServlet {
// myFile属性用来封装上传的文件 , 这个名称是固定的,接口文档里写了,trackdata
private File trackdata;
/*trackdataContentType, trackdataFileName 这两个参数没有,可能需要自己封装*/
// myFileContentType属性用来封装上传文件的类型
private String trackdataContentType;
// myFileFileName属性用来封装上传文件的文件名
private String trackdataFileName;
public File getTrackdata() {
return trackdata;
}
public void setTrackdata(File trackdata) {
this.trackdata = trackdata;
}
public String getTrackdataContentType() {
return trackdataContentType;
}
public void setTrackdataContentType(String trackdataContentType) {
this.trackdataContentType = trackdataContentType;
}
public String getTrackdataFileName() {
return trackdataFileName;
}
public void setTrackdataFileName(String trackdataFileName) {
this.trackdataFileName = trackdataFileName;
}
private static final long serialVersionUID = 1L;
public UploadServlet() {
super();
}
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
uploadFile(request);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.print("true");
out.flush();
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
uploadFile(request);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.print("true");
out.flush();
out.close();
}
public void init() throws ServletException {
// Put your code here
}
/**
* 格式化日期为指定格式的字符串
*
* @param date
* @param pattern
* @return
*/
public static String formatDate(Date date, String pattern) {
String result = "";
if (date != null) {
if (pattern == null) {
pattern = "yyyy-MM-dd";
}
result = DateFormatUtils.format(date, pattern);
}
return result;
}
/**
*
* @user 老何
* @2019年1月2日
* @return
*/
public boolean uploadFile(HttpServletRequest request){
try {
InputStream is = request.getInputStream();
//trackdataFileName = request.getParameter("trackdataFileName");
//基于myFile创建一个文件输入流
//InputStream is = new FileInputStream(trackdata);
// 设置上传文件目录
String uploadPath="d://upload//product";
File toFileDir = new File(uploadPath);
if(!toFileDir.exists()){
toFileDir.mkdir();//如果路径不存在就先创建路径
}
String format = "heqh.pdf";
//String format = trackdataFileName.substring(trackdataFileName.lastIndexOf("."));
String fn = formatDate(new Date(), "yyyyMMddHHmmss");
String dicPath ="//"+fn+format;
// 设置目标文件
File toFile = new File(uploadPath+dicPath);
// 创建一个输出流
OutputStream os;
os = new FileOutputStream(toFile);
//设置缓存
byte[] buffer = new byte[1024];
int length = 0;
//读取myFile文件输出到toFile文件中
while ((length = is.read(buffer)) > 0) {
os.write(buffer, 0, length);
}
//关闭输入流
is.close();
//关闭输出流
os.close();
}catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
}
3、index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String ctx = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>高拍仪测试界面</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="js/jquery-1.8.3.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script>
// ------------------------------------- 高拍仪相关操作 ------------------------------ //
var myfilename, files = [], currDir = '', fName=0;
/** 打开扫描仪 --> 开始 */
function Start1_onclick()
{
$("#captrue").show();
setTimeout(function(){
xz('90');
},200);
}
/** 旋转 --> 右转,左转,翻转(90,180,270) */
function xz(jd){
//方向旋转
captrue.vSetResolution(5);
captrue.bStopPlay();
var str = captrue.bStartPlayRotate (jd);
captrue.bSetMode(3);//自动描边
captrue.bStartPlay();
captrue.vSetImageQuality(50);//图片保存的压缩率(区间:1-100,默认值:70)
captrue.vSetSkewFlag(true);//自动矫正标志(TRUE:矫正,FALSE:不矫正)
captrue.vSetDelHBFlag(true);//黑边去除标志(TRUE:去除,FALSE:不去除)
captrue.bSetMode(1);
captrue.bSetImageArea (200,200,9800,9800);
}
/** 开始拍照 --> 拍照(原单张拍照) */
function cszp(){
getFileName();
captrue.bSaveJPG(currDir ,myfilename);
}
// 创建文件目录 currDir,并添加文件名到 files
function getFileName(){
var myDate = new Date();
var yy=myDate.getFullYear(); // 获取完整的年份(4位,1970-????)
var mm=myDate.getMonth()+1; //获取当前月份(0-11,0代表1月)
var dd=myDate.getDate(); //获取当前日(1-31)
var hh=myDate.getHours(); //获取当前小时数(0-23)
var m=myDate.getMinutes(); //获取当前分钟数(0-59)
var ss=myDate.getSeconds(); //获取当前秒数(0-59)
var fileName=yy+""+mm+""+dd+""+hh+""+m+""+ss;
//第一次上传创建一个新的目录,连拍的时候,如果有了, 就还在此目录, 当上传成功后,currDir清空,又重新生成目录
if( currDir.length == 0 ) {
currDir = "d:\\upload\\"+ fileName +"\\";
captrue.bCreateDir(currDir); // 创建目录
}
myfilename = ++fName;
files.push(myfilename);
}
/** 上传 --> 上传 */
function doUpload() {
if(files.length == 0) {
alert('您还没有拍摄照片');
return;
}
proFile();
jsUpload();
}
//生成pdf
/*************************************************************************/
//BOOL bReNameFile(LPCTSTR toPath, LPCTSTR fromPath)
/*************************************************************************/
/** 函数名称:bReNameFile
* 功能描述:重命名文件或者目录
* 输入参数:toPath——重命名后的文件或者目录的路径
fromPath——重命名前的文件或者目录的路径
* 输出参数:无
* 返回值: TRUE——成功
FALSE——失败
* 例如: m_cap. bReNameFile ("D:\\ tif_New.tif", "D:\\ tif.tif"); */
function proFile() {
captrue.bSavePDFStart(currDir,'1');//开始保存pdf
for(var aa=0; aa<files.length; aa++) {
if( captrue.bReNameFile(currDir+"N"+(aa+1)+".jpg", currDir+(aa+1)+".jpg") ) {
captrue.bAddPDFColorPage ( currDir+"N"+(aa+1)+".jpg", 0.525 ); //吧图片添加进入pdf,并设置像素
}
}
captrue.bSavePDFEnd () ;//结束保存pdf
}
//如果上传失败,那再吧文件名修改回来
function proFileB() {
for(var aa=0; aa<files.length; aa++) {
captrue.bReNameFile( currDir+(aa+1)+".jpg", currDir+"N"+(aa+1)+".jpg" )
}
}
function jsUpload(){
if(files.length == 0) {
alert('您还没有拍摄照片');
return;
}
var f = currDir +'upload.pdf';
if( captrue.bReNameFile(currDir+"upload.pdf", currDir+"1.pdf") ) {
var flag = false;
//第四个参数,有时候需要传全路径,即加上http://ip:端口/项目名,servlet不能加
flag = captrue.bUpLoadImage(f, "127.0.0.1", "8080", "/gpy/servlet/UploadServlet");
if(flag) {
alert("上传成功!");
captrue.bDeleteFile(currDir);
currDir = ''; files = []; myfilename = ''; fName=0;
} else {
proFileB();
alert('上传失败,请重新上传');
}
} else {
proFileB();
alert('pdf 转换失败,请重新上传');
}
}
/** 预览 --> 预览 */
function doView() {
if(files.length == 0) {
alert('您还没有拍摄照片')
return;
}
captrue.bDispPath(currDir);
}
/** 参数设置 */
function ParaSetPIN_onclick() {
captrue.vSetCapturePin();
captrue.bStartPlay(); // 显示主摄像头视频源
}
/** 设置曝光度 */
function changeExposure(){
var v = $('#bgd').val();
if(v==''){
return;
}
captrue.vSetExposure(v);//曝光相对值(区间:0-100)
}
/** 操作提醒 */
function openSm(){
$('#smDiv').show();
$('#smIframe').attr('src','smsm.html');
$('#smDiv').dialog({
title:'扫描说明',
width:640,
height:520,
modal:true,
closed:true,
buttons:[{
text:'关闭',
handler:function(){
$('#smDiv').dialog('close');
}
}]
});
$('#smDiv').dialog('open');
}
</script>
</head>
<body>
<div region="east" border="false" split="true" style="width: 1000px" >
<table style="width: 100%;height: 95%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="350px"><table id="txsmTable" contenteditable="true"></table></td>
<td>
<object classid="clsid:454C18E2-8B7D-43C6-8C17-B1825B49D7DE" id="captrue" style = "width:100%;height:640px;" ></object>
</td>
<td width="150" valign="top" style="padding:10px 10px 0px 10px">
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="text-align:center;color:#0563ae; font-size:14px; font-weight:bolder;background-color: #CCCCCC;">
<tr>
<td >
<img title="打开扫描仪" src="images//fxicon1.png" name="picture" border="0" align="middle" onMouseDown="this.src='images//fxicon1-1.png'" onMouseUp="this.src='images//fxicon1.png'" draggable="false" onClick="Start1_onclick()"/>
</td>
<td>
<img title="开始拍照" onclick="cszp()" src="images//funicon1-1.png" name="picture" border="0" align="middle" onMouseDown="this.src='images//funicon1.png'" onMouseUp="this.src='images//funicon1-1.png'" draggable="false"/>
</td>
</tr>
<tr>
<td height="25" title="打开扫描仪">开始</td>
<td onclick="cszp()" title="扫描当前页">拍照</td>
</tr>
<tr>
<td height="52">
<img onclick="xz('0');" src="images//fxicon2.png" name="picture" border="0" align="middle" onMouseDown="this.src='images//fxicon2-1.png'" onMouseUp="this.src='images//fxicon2.png'" draggable="false"/>
</td>
<td>
<%--
<img onclick="cszplp();" title="可使用键盘'空格键'进行操作" src="images//funicon2-1.png" name="picture" border="0" align="middle" onMouseDown="this.src='images//funicon2.png'" onMouseUp="this.src='images//funicon2-1.png'" draggable="false"/>
--%>
<img onclick="doUpload();" title="可使用键盘'空格键'进行操作" src="images//funicon2-1.png" name="picture" border="0" align="middle" onMouseDown="this.src='images//funicon2.png'" onMouseUp="this.src='images//funicon2-1.png'" draggable="false"/>
</td>
</tr>
<tr>
<td onclick="xz('0');" height="25">右转</td>
<%--
<td onclick="cszplp();" title="可使用键盘'空格键'进行操作">彩色连拍</td>
--%>
<td onclick="doUpload();" title="可使用键盘'空格键'进行操作">上传</td>
</tr>
<tr>
<td height="49"><img onclick="xz('180');" src="images//fxicon3.png" name="picture" border="0" align="middle" onMouseDown="this.src='images//fxicon3-1.png'" onMouseUp="this.src='images//fxicon3.png'" draggable="false"/></td>
<td>
<%--
<img title="可使用键盘'回车'进行上传操作" onclick="stoplp();" src="images//funicon4-1.png" name="picture" border="0" align="middle" onMouseDown="this.src='images//funicon4.png'" onMouseUp="this.src='images//funicon4-1.png'" draggable="false"/>
--%>
<img title="预览" onclick="doView();" src="images//funicon4-1.png" name="picture" border="0" align="middle" onMouseDown="this.src='images//funicon4.png'" onMouseUp="this.src='images//funicon4-1.png'" draggable="false"/>
</td>
</tr>
<tr>
<td height="25" onclick="xz('180');" >左转</td>
<%--
<td onclick="stoplp();" title="可使用键盘'回车'进行上传操作">连拍完成</td>
--%>
<td onclick="doView();" title="预览">预览</td>
</tr>
<tr>
<td height="49"><img onclick="xz('270');" src="images//fxicon4.png" name="picture" border="0" align="middle" onMouseDown="this.src='images//fxicon4-1.png'" onMouseUp="this.src='images//fxicon4.png'" draggable="false"/></td>
<td>
<img title="设置分辨率" src="images//funicon5-1.png" draggable="false" onClick="ParaSetPIN_onclick()"/>
</td>
</tr>
<tr>
<td height="25" onclick="xz('270');" >翻转</td>
<td title="设置分辨率">参数设置</td>
</tr>
<tr>
<td title="扫描操作以及注意事项说明"><img onclick="openSm()" src="images//icontis-1.png" draggable="false" /></td>
<td height="49"><img title="设置曝光度0-100" src="images//funicon5-1.png" draggable="false" onClick="changeExposure()"/>
</td>
</tr>
<tr>
<td title="扫描操作以及注意事项说明">操作提醒</td>
<td height="25" title="设置曝光度0-100">设置曝光度<br/><input type="text" size="5" id="bgd"></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
</html>