java生成解析二维码
来源:互联网 发布:js数组去重的方法sp 编辑:程序博客网 时间:2024/05/29 03:30
- 说明
- zxing生成二维码示例
- zxing解析二维码示例
- 一个基于zxing第三方开源项目
- 代码地址
说明
本文介绍使用zxing
来生成和解析二维码。
maven坐标如下:
<dependency> <groupId>com.google.zxing</groupId> <artifactId>core</artifactId> <version>3.3.0</version></dependency>
1 zxing生成二维码示例
/** * 生成二维码并写到指定的输出流 * * @param width * 二维码宽度 * @param height * 二维码高度 * @param content * 二维码内容 * @param dest * 输出目标,可以是 * {@link FileOutputStream}、{@link ServletOutputStream}等任何输出流 * @throws IOException * @throws WriterException */public void generateQRCode(int width, int height, String content, OutputStream dest) throws IOException, WriterException { Map<EncodeHintType, Object> map = new HashMap<>(); // 编码方式 map.put(EncodeHintType.CHARACTER_SET, "utf-8"); // 纠错级别--中级 map.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M); // 内边距 map.put(EncodeHintType.MARGIN, 2); // 生成二维码 BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, map); // 写入到任何输出流皆可 MatrixToImageWriter.writeToStream(matrix, "png", dest);}
2 zxing解析二维码示例
/** * 从输入流解析二维码 * * @param inputStream * @return * @throws IOException * @throws NotFoundException */@SuppressWarnings("unchecked")public Result parseQRCode(InputStream inputStream) throws IOException, NotFoundException { @SuppressWarnings("rawtypes") Map map = new HashMap(); map.put(EncodeHintType.CHARACTER_SET, "utf-8"); BinaryBitmap binaryBitmap = null; BufferedImage bufferedImage = ImageIO.read(inputStream); binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(bufferedImage))); Result result = new MultiFormatReader().decode(binaryBitmap, map); return result;}
3 一个基于zxing第三方开源项目
地址:https://github.com/kenglxn/QRGen
使用示例:
QRCode.from("https://github.com/kenglxn/QRGen")// .withSize(400, 400)// .withHint(EncodeHintType.CHARACTER_SET, "UTF-8")// .withErrorCorrection(ErrorCorrectionLevel.M)// .withHint(EncodeHintType.MARGIN, 2)// .writeTo(new FileOutputStream(new File("/Users/hylexus/tmp/t.png")));
代码地址
https://github.com/hylexus/blog-src/tree/master/qr-code
0 0
- Java生成二维码解析二维码
- java 生成二维码,解析二维码
- JAVA生成解析二维码
- java生成/解析二维码
- java生成解析二维码
- java生成二维码和解析二维码
- Java---利用Zing生成二维码、解析二维码
- JAVA生成二维码和解析二维码
- java生成二维码与解析二维码
- Java生成解析二维码源码
- java生成解析二维码功能
- java二维码生成与解析
- Java 二维码生成与解析
- java 二维码生成与解析
- Java二维码生成和解析
- java二维码工具类:生成二维码和解析二维码
- (Java功能篇)JAVA生成解析二维码
- java二维码生成与解析代码实现
- linux 压缩解压归档
- HDOJ 1074 Doing Homework (状压DP)
- C++ void指针解析
- Android中通知栏的使用
- 传奇服务端各文件用途说明
- java生成解析二维码
- vue学习系列-认识vue.js
- Xutils3.0简单的应用Dome
- 51nod 1080 两个数的平方和【二分】
- SpringMVC文件上传
- UVA_1025 A Spy in the Metro(dp)
- 无限接近圆周率
- 紫书进度
- 闭包与柯里化的小题目