在JAVA生成二维码的基础上进行解析
生成二维码博客地址:http://blog.youkuaiyun.com/qciwyy/article/details/77161154
新建类ReadRQCode.java
package com.imooc.zxing;
import java.awt.image.BufferedImage;
import java.io.File;
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();
}
}
}
解析结果Hello World
二维码类型QR_CODE
二维码内容Hello World