Java实现解析二维码
前几天说了二维码的生成,今天说下二维码的解析
public static void main(String[] args) throws NotFoundException, IOException {
File file = new File("你的二维码路径", "二维码名称");
//定义二维码的参数
HashMap hints = new HashMap();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
//L级:约可纠错7%的数据码字,M级:约可纠错15%的数据码字,Q级:约可纠错25%的数据码字,H级:约可纠错30%的数据码字
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.Q);
hints.put(EncodeHintType.MARGIN, 2);
MultiFormatReader formatReader = new MultiFormatReader();
BufferedImage image = ImageIO.read(file);
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(image)));
Result result = formatReader.decode(binaryBitmap, hints);
}