QR Code码,是由Denso公司于1994年9月研制的一种矩阵二维码符号,它具有一维条码及其它二维条码所具有的信息容量大、可靠性高、可表示汉字及图象多种文字信息、保密防伪性强等优点。
先下载QRCode.jar包:https://pan.baidu.com/s/1Pb9XzWKhumgwaYrE90vyWg
二、代码实例
1、生成二维码
//加密:文字信息 -> 二维码
public static void encoderQRCode(String content, String imgPath, String imgType, int size) throws Exception{
//RenderedImage是一个接口,因此要找到它的实现类 BufferedImage
//RenderedImage bufferedImage = null;
//代表内存中的一张图片
BufferedImage bufferedImage = generateQRCodeCommon(content, imgType, size);
//设置图片格式,与输出的路径
ImageIO.write(bufferedImage, “jpg”, new File(“H:/qrcode.jpg”));
}
//产生一个二维码的BufferedImage
private static BufferedImage generateQRCodeCommon(String content, String imgType, int size) throws Exception{
//QRCode对象:字符串转为boolean[][]
Qrcode qrcode