没有合适的资源?快使用搜索试试~ 我知道了~
首页java实现电脑端扫描二维码
java实现电脑端扫描二维码
756 浏览量
更新于2023-05-30
评论
收藏 70KB PDF 举报
主要为大家详细介绍了java实现电脑端扫描二维码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
资源详情
资源评论
资源推荐

java实现电脑端扫描二维码实现电脑端扫描二维码
主要为大家详细介绍了java实现电脑端扫描二维码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了java实现电脑端扫描二维码的具体代码,供大家参考,具体内容如下
说明:js调去电脑摄像头拍照,然后获取图片base64位编码,再将base64为编码转为bolb,通过定时异步上传到后台,在后台对图片文
件进行解码,返回解码结果到页面,然后页面重新加载结果(url)
第一种方式引入js
<script type="text/javascript" src="${basePath}js/jquery-1.9.min.js"></script>
<script type="text/javascript" src="${basePath}js/jquery.webcam.min.js"></script>
第二种方式引入js
<script type="text/javascript" src="${basePath}js/jquery-1.9.min.js"></script>
<!-- 这个应该是需要的 -->
<script type="text/javascript" src="${basePath}js/jquery.qrcode.min.js"></script>
后台java代码maven引入jar包
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>qrcode-utils</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.3.3</version>
</dependency>
后台代码处理方式:
public class EwmDescode {
/**
* 解析二维码
*
* @param input
* 二维码输入流
*/
public static final String parse(InputStream input) throws Exception {
Reader reader = null;
BufferedImage image;
try {
image = ImageIO.read(input);
if (image == null) {
throw new Exception("cannot read image from inputstream.");
}
final LuminanceSource source = new BufferedImageLuminanceSource(image);
final BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
final Map<DecodeHintType, String> hints = new HashMap<DecodeHintType, String>();
hints.put(DecodeHintType.CHARACTER_SET, "utf-8");
// 解码设置编码方式为:utf-8,
reader = new MultiFormatReader();
return reader.decode(bitmap, hints).getText();
} catch (IOException e) {
e.printStackTrace();
throw new Exception("parse QR code error: ", e);
} catch (ReaderException e) {
e.printStackTrace();
throw new Exception("parse QR code error: ", e);
}
}
/**
* 解析二维码
*
* @param url
* 二维码url
*/
public static final String parse(URL url) throws Exception {
InputStream in = null;
try {
in = url.openStream();
return parse(in);
} catch (IOException e) {
e.printStackTrace();
throw new Exception("parse QR code error: ", e);
} finally {
IOUtils.closeQuietly(in);
}
















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0