zxing生成二维码和读取二维码
当然,首先要导入zxing的jar包。

生成二维码代码:
package com.imooc.zxing; import java.io.File;
import java.nio.file.Path;
import java.util.HashMap; import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; /**
* java代码生成二维码<br>
*
* @author Administrator
*
*/
public class CreateQRCode { public static void main(String[] args) {
int width = 300;
int height = 300;
String format = "png";
String content = "http://www.hupu.com"; // 定义二维码参数
HashMap hints = new HashMap();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");// 字符集
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);// 纠错级别
hints.put(EncodeHintType.MARGIN, 2);// 空白 try {
BitMatrix bitMatrix = new MultiFormatWriter().encode(content,
BarcodeFormat.QR_CODE, width, height, hints);
Path file = new File("E:/code/img.png").toPath(); MatrixToImageWriter.writeToPath(bitMatrix, format, file); } catch (Exception e) {
e.printStackTrace();
} } }
生成二维码如下:

读取二维码:
package com.imooc.zxing; import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.HashMap; import javax.imageio.ImageIO; import com.google.zxing.BinaryBitmap;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.Result;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer; public class ReadQRCode { public static void main(String[] args) {
try {
MultiFormatReader formatReader = new MultiFormatReader();
File file = new File("E:/code/img.png");
BufferedImage image = ImageIO.read(file); BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
new BufferedImageLuminanceSource(image))); HashMap hints = new HashMap();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");// 字符集 Result result = formatReader.decode(binaryBitmap, hints); System.out.println("解析之后的结果:" + result.toString());
System.out.println("二维码格式类型:" + result.getBarcodeFormat());
System.out.println("二维码文本内容:" + result.getText()); } catch (Exception e) {
e.printStackTrace();
} } }
代码运行结果:

zxing生成二维码和读取二维码的更多相关文章
- 【java】google的zxing架包生成二维码和读取二维码【可带文字和logo】
承接RC4生成不重复字符串的需求之后,因为优惠码要方便用户使用的缘故,所以思来想去,觉得还是直接生成二维码给用户直接扫比较实用,也不用用户专门记录冗长的优惠码编号. ================= ...
- ZXing生成二维码、读取二维码
使用谷歌的开源包ZXing maven引入如下两个包即可 <dependency> <groupId>com.google.zxing</groupId> & ...
- 使用zxing生成彩色或带图片的二维码
<!-- https://mvnrepository.com/artifact/com.google.zxing/core --> <dependency> <group ...
- PHP 二维码解码 (读取二维码)
#zbar wget http://ncu.dl.sourceforge.net/project/zbar/zbar/0.10/zbar-0.10.tar.bz2 yum install gtk2 g ...
- jquery-qrcode 生成和读取二维码
首先要导入jar包(生成二维码的jar和读取二维码的jar) 生成二维码: package com.imooc.qrcode; import java.awt.Color; import java.a ...
- ZXing 生成、读取二维码(带logo)
前言 ZXing,一个支持在图像中解码和生成条形码(如二维码.PDF 417.EAN.UPC.Aztec.Data Matrix.Codabar)的库.ZXing(“zebra crossing”)是 ...
- ZXing 生成、解析二维码图片的小示例
概述 ZXing 是一个开源 Java 类库用于解析多种格式的 1D/2D 条形码.目标是能够对QR编码.Data Matrix.UPC的1D条形码进行解码. 其提供了多种平台下的客户端包括:J2ME ...
- (转)ZXing生成二维码和带logo的二维码,模仿微信生成二维码效果
场景:移动支付需要对二维码的生成与部署有所了解,掌握目前主流的二维码生成技术. 1 ZXing 生成二维码 首先说下,QRCode是日本人开发的,ZXing是google开发,barcode4j也是老 ...
- ZXing生成条形码、二维码、带logo二维码
采用的是开源的ZXing,Maven配置如下,jar包下载地址,自己选择版本下载,顺便推荐下Maven Repository <!-- https://mvnrepository.com/art ...
随机推荐
- atom编辑器插件atom-ternjs
这是官方文档:https://atom.io/packages/atom-ternjs 官方介绍: JavaScript code intelligence for atom with Tern. A ...
- 高性能网络编程(1)—accept建立连接(待研究)
阿里云博客上一篇感觉还不错的文章,待研究,原文链接如下: http://blog.aliyun.com/673?spm=5176.7114037.1996646101.3.oBgpZQ&pos ...
- Linux网络属性配置命令和管理详解
一.Linux网络属性配置 1.Linux主机接入到网络方式 IP/NETMASK:实现本地网络通信 路由(网关):可以进行跨网络通信 DNS服务器地址:基于主机名的通信,Linux可以有三个DNS地 ...
- HDU 2829 Lawrence(斜率优化DP O(n^2))
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2829 题目大意:有一段铁路有n个站,每个站可以往其他站运送粮草,现在要炸掉m条路使得粮草补给最小,粮草 ...
- linux下不解包查看tar包文件内容
为减少日志文件占用的空间,很多情况下我们会将日志文件以天或周为周期打包成tar.gz 包保存.虽然这样做有利空间充分利用,但当我们想查看压缩包内的内容时确很不方便.如果只是一个tar.gz文件,可以将 ...
- Python+Selenium 自动化实现实例-Link 捕捉元素的几种方法
from selenium import webdriver driver = webdriver.Chrome() driver.get("http://www.baidu.com&quo ...
- LeetCode解题报告—— Regular Expression Matching
Given an input string (s) and a pattern (p), implement regular expression matching with support for ...
- AC日记——Mato的文件管理 bzoj 3289
3289 思路: 莫队求区间逆序对个数,树状数组维护: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 500 ...
- Openstack 云主机深入了解 (十六)
一)云主机深入了解 1.云主机在计算节点以进程方式运行 2.监听vnc的端口,vnc默认端口从5900开始, 多台云主机,端口递增 3.云主机桥接网卡,与宿主机联通网络 提示:在openstack环境 ...
- gradle打包分编译环境
gradle打包分测试.开发.生产环境 buildTypes { debug { signingConfig signingConfigs.myConfig buildConfigField(&quo ...