上一篇文章说了二维码的生成,这次说二维码的解析
步骤:
- 导入上次的jar包
- 编写解析代码
try {
//解析二维码的类
MultiFormatReader multiFormatReader=new MultiFormatReader();
//要解析的二维码的图片
File image=new File("d:/Img.png");
BufferedImage bufferedImage= ImageIO.read(image);
BinaryBitmap binaryBitmap=new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(bufferedImage)));
//二维码的参数设置
HashMap hints=new HashMap();
hints.put(EncodeHintType.CHARACTER_SET,"utf-8");//设置二维码的编码
//得到解析结果,
Result result= multiFormatReader.decode(binaryBitmap,hints);
//打印结果信息
System.out.println("解析结果:"+result.toString());
System.out.println("二维码格式类型"+result.getBarcodeFormat());
System.out.println("二维码文本内容:"+result.getText());
}catch (Exception e){
System.out.println(e);
}
解析结果: