博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java框架---->zxing框架的使用
阅读量:4556 次
发布时间:2019-06-08

本文共 1373 字,大约阅读时间需要 4 分钟。

  今天我们就来学习一下zxing的用法,这里只涉及到java se的部分。

zxing的学习

如果在java se环境中使用zxing,需要在maven的pom.xml中添加依赖:

com.google.zxing
javase
3.3.0

一、根据内容生成二维码

public void encodeNoReturn(String content) {    try {        Path path = new File("file/huhx.png").toPath();        BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, 300, 300);        MatrixToImageWriter.writeToPath(matrix, "png", path);    } catch (Exception e) {        e.printStackTrace();    }}

 

二、根据二维码读取内容

public static void main(String[] args) {    File file = new File("file/huhx.jpg");    BufferedImage bufferedImage = null;    try {        bufferedImage = ImageIO.read(file);    } catch (IOException e) {        e.printStackTrace();    }    LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));    Hashtable
hints = new Hashtable
(); hints.put(DecodeHintType.CHARACTER_SET, "GBK"); Result result = null; try { result = new MultiFormatReader().decode(bitmap, hints); } catch (NotFoundException e) { e.printStackTrace(); } String url = result.getText(); System.out.println(url);}

 

友情链接

  • zxing的github地址:

 

转载于:https://www.cnblogs.com/huhx/p/baseusejavazxing1.html

你可能感兴趣的文章
Phone List HDU - 1671(字典树)
查看>>
I Hate It HDU - 1754(线段树找区间最大值)
查看>>
牛客假日团队赛11 H 过河卒(路径条数dp)
查看>>
P3374 树状数组 1(单点修改求和)
查看>>
Apache Mina-1
查看>>
复健运动poj2431
查看>>
文件关联与关联文件
查看>>
tomcat path配置
查看>>
windows lwp 乱码问题
查看>>
android锁屏和finish()后activity生命周期的变化
查看>>
为公司制作CRM截图
查看>>
LeetCode145 Binary Tree Postorder Traversal Java题解(递归 迭代)
查看>>
UVa 10450 - World Cup Noise
查看>>
Android 调用QQ登录
查看>>
Educational #39C
查看>>
threejs学习笔记(7)
查看>>
NOIP2016
查看>>
docker使用笔记
查看>>
推荐一款在IntelliJ IDEA中使用微信/QQ的插件
查看>>
github简单操作
查看>>