dqpi_lyy
2018-12-25 10:18
com.google.zxing.NotFoundException
try { MultiFormatReader multiFormatReader = new MultiFormatReader(); File file = new File("D:/jar/jk.jpg"); BufferedImage image = ImageIO.read(file); Map<DecodeHintType, Object> tmpHintsMap = new EnumMap<DecodeHintType, Object>( DecodeHintType.class); // 解码设置编码方式为:utf-8, tmpHintsMap.put(DecodeHintType.CHARACTER_SET, "utf-8"); //优化精度 tmpHintsMap.put(DecodeHintType.TRY_HARDER, Boolean.TRUE); //复杂模式,开启PURE_BARCODE模式 tmpHintsMap.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE); BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(image))); Result result = multiFormatReader.decode(binaryBitmap, tmpHintsMap); System.out.println("二维码内容 : " +result.toString()); System.out.println("二维码格式 : " +result.getBarcodeFormat()); System.out.println("二维码文本 : " +result.getText()); } catch (NotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
网上搜了 说是设置那几个属性 设置了还是报错 图片是我手机拍的 然后进行截图解析
图片不清楚可能会导致解析时将logo也看成二维码的黑条一起解析。
Java生成二维码
84564 学习 · 224 问题
相似问题