使用zxing解析二维码图片
来源:互联网 发布:高中网络辅导班哪家好 编辑:程序博客网 时间:2024/04/29 13:39
在上一篇文章中,分享了立牌二维码的生成,本篇文章介绍采用zxing解析二维码图片。
下面是具体的步骤:
1.在解析的时,需要使用到javase.jar包中的BufferedImageLuminanceSource类,所以需先在工程中导入javase.jar包。
下载地址:http://download.csdn.net/detail/mr_smile2014/9715554
2.下面提供传图片地址和传图片BufferedImage的方式,代码如下:
/** * * @Title: deqrcode * @Description: 解析二维码 * @param imgPath * 二维码图片路径 * @return void 返回类型 * @throws */@SuppressWarnings({ "rawtypes", "unchecked" })public static String deqrcode(String imgPath) {try {File file = new File(imgPath);// 获取该图片文件BufferedImage image = ImageIO.read(file);if (image == null) {System.out.println("未获取到图片对象");}LuminanceSource source = new BufferedImageLuminanceSource(image);BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));Hashtable hints = new Hashtable();// 将图片反解码为二维矩阵hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");Result result = new MultiFormatReader().decode(bitmap, hints);// 将该二维矩阵解码成内容String resultStr = result.getText();return resultStr;} catch (Exception ex) {ex.printStackTrace();}return null;}/** * * @Title: deqrcode * @Description: 解析二维码图片 * @param image * 二维码图片对象 * @return String 二维码文本值 * @throws */@SuppressWarnings({ "rawtypes", "unchecked" })public static String deqrcode(BufferedImage image) {try {if (image == null) {System.out.println("image参数不能为空");}LuminanceSource source = new BufferedImageLuminanceSource(image);BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));Hashtable hints = new Hashtable();// 将图片反解码为二维矩阵hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");Result result = new MultiFormatReader().decode(bitmap, hints);// 将该二维矩阵解码成内容String resultStr = result.getText();return resultStr;} catch (Exception ex) {ex.printStackTrace();}return null;}
3.测试:
测试的二维码图片:
测试的代码:
public class codeTest {public static void main(String[] args) throws Exception {// 根据图片文件路径解析二维码String result = QCodeUtils.deqrcode("F:/qrcode/text/111.png");System.out.println("文件地址解析结果:"+result);// 根据图片BufferedImage对象解析二维码File file = new File("F:/qrcode/text/111.png");// 获取该图片文件BufferedImage image = ImageIO.read(file);String result1 = QCodeUtils.deqrcode(image);System.out.println("image对象解析结果:"+result1);}}
4.测试效果:
---------------------------------------------------------------------------版权声明------------------------------------------------------------------------------------------
版权声明:本文为博主原创文章,未经博主允许不得转载。博客地址:http://blog.csdn.net/mr_smile2014
4 0
- 使用zxing解析二维码图片
- 使用zxing生成二维码图片,并解析
- 二维码之zxing二维码解析图片资源
- 二维码之zxing二维码解析图片资源
- 【ZXing】Android使用zxing生成二维码图片
- 使用ZXing创建二维码和解析二维码
- ZXing之二维码解析图片资源
- Java使用谷歌的zxing生成二维码Qrcode并解析提取二维码图片内容
- 使用zxing 生成和解析二维码
- 使用zxing生成和解析二维码
- 使用zxing工具包创建和解析二维码
- 使用谷歌 zxing 生成、解析二维码
- 解析二维码内容(使用zxing方式)
- 使用zxing生成与解析二维码
- 使用zxing生成和解析二维码
- 使用zxing生成与解析qr二维码
- 使用zxing解析二维码抛出com.google.zxing.NotFoundException 解决方案
- Zxing图片识别 从相册选二维码图片解析总结
- 彻底弄懂 Http 缓存机制 - 基于缓存策略三要素分解法
- 执行Fragment的getActivity()方法返回null
- 【BZOJ 1923】 [Sdoi2010]外星千足虫 高斯消元
- 关于DEX字节码解释的网址
- Java中为IO流写一个快速关闭流的小工具
- 使用zxing解析二维码图片
- Android入门级之WebView的使用
- sql_sever单表查询的一些基本案例
- android开发 判断当前手机是否是阿里 yunOS 系统
- 关于git里面的everything up-to-date
- 移除不能识别的(invalid)utf8字符
- python基础知识之成员资格、len函数、max函数、min函数
- 第三章 决策树 3.3+3.4 测试算法:使用决策树执行分类
- 厉害的程序员相对于普通程序员,对于完成一个需求来说,除了更少的 bug,还有什么优势?