ZXingUtil { @SuppressWarnings({"rawtypes", "unchecked"}) public static String decodeQRCode(BufferedImage image) { MultiFormatReader formatReader = new MultiFormatReader(); LuminanceSource source = new BufferedImageLuminanceSource(image); Binarizer binarizer = new HybridBinarizer(source); BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer); HashMap hints = new HashMap(); hints.put(EncodeHintType.CHARACTER_SET, StandardCharsets.UTF_8); String codeContent = null; try { Result result = formatReader.decode(binaryBitmap, hints); codeContent = result.getText(); } catch (NotFoundException e) { logger.error("NotFoundException: [{}]", e); } return codeContent; } private  ZXingUtil(); static void generateQRCode(String content, String format, int width, int height, OutputStream stream, boolean isFill, BufferedImage logo); static void generateQRCode(String content, String format, int width, int height, File file, boolean isFill, BufferedImage logo); @SuppressWarnings({"rawtypes", "unchecked"}) static String decodeQRCode(BufferedImage image); static BufferedImage addLogoToImage(BufferedImage baseImage, BufferedImage logo);  }
@Test public void decodeQRCode() throws Exception { String content = "http: String format = "png"; String filePath = "C:/Users/Administrator/Desktop/test_img"; File dirPath = new File(filePath); if (!dirPath.exists()) { System.out.println("create filePath " + filePath + "," + dirPath.mkdirs()); } String imagePath = filePath + "/" + UUID.randomUUID().toString().substring(0, 8) + "." + format; File imageFile = new File(imagePath); ZXingUtil.generateQRCode(content, format, 200, 200, imageFile, true, null); BufferedImage bufferedImage = ImageIO.read(imageFile); String codeContent = ZXingUtil.decodeQRCode(bufferedImage); System.out.println("decodeQRCode result : " + codeContent); String logoName = "test_logo.png"; String logoPath = filePath + "/" + logoName; String addLogoPath = filePath + "/" + UUID.randomUUID().toString().substring(0, 8) + "." + format; File addLogoImage = new File(addLogoPath); ImageIO.write(ZXingUtil.addLogoToImage(bufferedImage, ImageIO.read(new File(logoPath))), format, addLogoImage); }