- 二维码的分类
- 线性堆叠式二维码
- 矩阵式二维码
- 邮政码
- 二维码的优点
1.高密度编码,信息容量大,可以容纳1850个大写字母,或者2710个数字,或者1108个字节,或者500多个汉字
- 编码范围广:把可以数字化的信息都可以进行编码
- 容错能力强
- 译码可靠性高,误码率不超过千万分之一
- 可引入加密措施
- 成本低,容易制作,耐用
- 二维码的缺点
- 成为病毒传播的新渠道
- 信息泄露
- QR Code
- 目前流行的三大标准
①PDF417:不支持中文
②DM:专利未公开,需要支付专利费用
③QR Code: 专利公开,支持中文 - jsp生成二维码方法
- 借助第三方,zxing和qrcode.jar
- js,如jQuery.qrcode.js
- zxing方式生成二维码
- 网址:https://github.com/zxing/zxing/releases
- 核心文件包有两个
![这里写图片描述](https://img-blog.csdn.net/20171127174306612?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaHVvYmFvdGlhbmRhbw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
- 将包里的核心包放在一个工程里,打成一个jar包,以供我们以后的开发使用
package com.fgy.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.WriterException
import com.google.zxing.client.j2se.MatrixToImageWriter
import com.google.zxing.common.BitMatrix
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
public class CreateQRCode {
public static void main(String[] args) {
int width = 300
int height = 300
String imageFormt = "png"
String content = "www.baidu.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("F:/code/img.png").toPath()
MatrixToImageWriter.writeToPath(bitMatrix, imageFormt, file)
} catch (Exception e) {
e.printStackTrace()
}
}
}