java使用zxing_在Java中使用Zxing读取QRCode
关于使用Zxing的一些问题…
我写下面的代码从图像中读取条形码:
public class BarCodeDecode
{
/**
* @param args
*/
public static void main(String[] args)
{
try
{
String tmpImgFile = "D:\\FormCode128.TIF";
Map tmpHintsMap = new EnumMap(DecodeHintType.class);
tmpHintsMap.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
tmpHintsMap.put(DecodeHintType.POSSIBLE_FORMATS, EnumSet.allOf(BarcodeFormat.class));
tmpHintsMap.put(DecodeHintType.PURE_BARCODE, Boolean.FALSE);
File tmpFile = new File(tmpImgFile);
String tmpRetString = BarCodeUtil.decode(tmpFile, tmpHintsMap);
//String tmpRetString = BarCodeUtil.decode(tmpFile, null);
System.out.println(tmpRetString);
}
catch (Exception tmpExpt)
{
System.out.println("main: " + "Excpt err! (" + tmpExpt.getMessage() + ")");
}
System.out.println("main: " + "Program end.");
}
}
public class BarCodeUtil
{
private static BarcodeFormat DEFAULT_BARCODE_FORMAT = BarcodeFormat.CODE_128;
/**
* Decode method used to read image or barcode itself, and recognize the barcode,
* get the encoded contents and returns it.
* @param whatFile image that need to be read.
* @param config configuration used when reading the barcode.
* @return decoded results from barcode.
*/
public static String decode(File whatFile, Map whatHints) throws Exception
{
// check the required parameters
if (whatFile == null || whatFile.getName().trim().isEmpty())
throw new IllegalArgumentException("File not found, or invalid file name.");
BufferedImage tmpBfrImage;
try
{
tmpBfrImage = ImageIO.read(whatFile);
}
catch (IOException tmpIoe)
{
throw new Exception(tmpIoe.getMessage());
}
if (tmpBfrImage == null)
throw new IllegalArgumentException("Could not decode image.");
LuminanceSource tmpSource = new BufferedImageLuminanceSource(tmpBfrImage);
BinaryBitmap tmpBitmap = new BinaryBitmap(new HybridBinarizer(tmpSource));
MultiFormatReader tmpBarcodeReader = new MultiFormatReader();
Result tmpResult;
String tmpFinalResult;
try
{
if (whatHints != null && ! whatHints.isEmpty())
tmpResult = tmpBarcodeReader.decode(tmpBitmap, whatHints);
else
tmpResult = tmpBarcodeReader.decode(tmpBitmap);
// setting results.
tmpFinalResult = String.valueOf(tmpResult.getText());
}
catch (Exception tmpExcpt)
{
throw new Exception("BarCodeUtil.decode Excpt err - " + tmpExcpt.toString() + " - " + tmpExcpt.getMessage());
}
return tmpFinalResult;
}
}
我尝试读取包含code128和QRCode的以下两个图像.
它可以适用于code128但不适用于QRCode.
任何人都知道为什么…
java使用zxing_在Java中使用Zxing读取QRCode相关推荐
- 太实用了!在Java的Word 文档中插入或读取艺术字
太实用了!在Java的Word 文档中插入或读取艺术字 简直不能太实用! 扫码关注<Java学研大本营>,加入读者群,分享更多精彩 艺术字是一组文本样式,允许您向文本添加设计元素,例如填充 ...
- java 读excel 流_Java中使用POI读取大的Excel文件或者输入流时发生out of memory异常参考解决方案...
原文:https://www.cnblogs.com/cksvsaaa/p/7280261.html 注意:此参考解决方案只是针对xlsx格式的excel文件! 背景 前一段时间遇到一种情况,服务器经 ...
- Java二维码工具类(使用zxing实现,可支持logo)
本工具类基于Google二维码框架zxing3.1.0实现. 1. pom.xml中依赖包设置 <dependency><groupId>com.google.zxing< ...
- Marco's Java【小工具篇 之 Google Zxing 二维码生成】
前言 二维码相信大家一定不陌生啦,去菜市场买菜,路边摊买个小吃都可以扫一扫,近几年来中国的二维码技术的普及也是大家有目共睹的,而二维码在其他国家虽然有用到,但极少,更没有说全国普及. 二维码又称二维条 ...
- java 枚举的继承_java中枚举类可以被继承吗?
java 枚举类 java中,使用关键字enum来定义枚举类,枚举类是一个特殊的类,大部分功能和普通类是一样的,区别为: ● 枚举类继承了java.lang.Enum类,而不是默认的Object类.而 ...
- jsp与java的关系_jsp教程中:jsp与servlet的区别和关系
jsp教程上:我们一定学了servlet,也学习了jsp,那么jsp与servlet的区别是什么呢,jsp与servlet又有什么关系呢?下面我们先创建一个demo.jsp的页面,然后tomcat运行 ...
- java comparable接口作用_Java 中 Comparable 接口的意义和用法
一, 为何需要实现Comparable接口 我们知道Collections类中包含很多对实现Collection接口的容器各种操作的静态方法. 当然, 其中最长用的莫过于排序了(Collections ...
- java makefile jar包_java makefile学习实践(编译的javac命令写在makefile中,运行命令java写在shell脚本中)...
学习makefile教程,ubuntu中文网 1.写一个简单的java项目,不需要外部jar,用的简单的 importjava.util.ArrayList;是可以从CLASSPATH环境变量中找到的 ...
- java for循环迭代_JAVA中的for-each循环与迭代
在学习java中的collection时注意到,collection层次的根接口Collection实现了Iterable接口(位于java.lang包中),实现这个接口允许对象成为 "fo ...
- linux java 栈_关于Java中栈与堆的思考
1. 栈(stack)与堆(heap)都是Java用来在Ram中存放数据的地方.与C++不同,Java自动管理栈和堆,程序员不能直接地设置栈或堆. 2. 栈的优势是,存取速度比堆要快,仅次于直接位于C ...
最新文章
- jquery学习(六)-jquery中的动画
- 第18章 Linux集群架构
- deeplearning4j – 分布式DL开源项目
- antd 设置表头属性_使用表数据自定义React Antd表头
- 计算机用语优秀怎么算,计算机专业用语
- Flutter 日期选择器与时间选择器
- iOS 使用符号断点定位警告约束警告-[LayoutConstraints] Unable to simultaneously satisfy constrai...
- 这些神经网络调参细节,你都了解了吗
- effective c++ 第六章
- paip.提升用户体验----自定义移位操作符重载
- jspstudy启动mysql失败_二、MySQL启动失败故障思路
- android webview 跳转到浏览器,Android WebView或手机浏览器打开连接问题解决办法总结...
- 山特服务器硬盘480g,【02311VHS N480SSDW2SPA 480GB SATA SSD 华为服务器固态硬盘】价格_厂家 - 中国供应商...
- 【网络】路由器集成锐捷认证
- python中单引号的作用_python里的单引号和双引号的有什么作用
- springboot中对各个层的理解以及流程
- 驱动程序如何手动卸载与更新
- Glusterfs|ceph实现分布式存储
- SecureCRT 命令行备注
- 【基本功】深入剖析Swift性能优化