zxing API在扫描图像中找不到QR码?

时间:2019-05-17 05:40:08

标签: java web zxing zbar

我正在尝试从扫描的pdf解码qrcode,但是该库无法读取QR码。抛出未找到的qrcode错误the scanned image sample 如果图像质量有问题,谁能建议zxing库使图像可读性

    private static void decodeQRCode(String myDirectoryPath) throws IOException {
        try {
        File dir = new File(myDirectoryPath);
        File[] directoryListing = dir.listFiles();
         if (directoryListing != null) {
         for (File child : directoryListing) {
        if (child.toString().contains(".tif") || child.toString().contains(".png")) {
         // Do something with child
        try {
             System.out.println(child.getName());
        BufferedImage bufferedImage = ImageIO.read(child);
         // BufferedImage bufferedImage = new PdfReader(qrCodeimage);

        Map<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
        hints.put(DecodeHintType.OTHER, true);

        LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);

        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

        Result result = new MultiFormatReader().decode(bitmap);

        System.out.println(result+" "+child.getName());

        } catch (NotFoundException e) {

         System.out.println("There is no QR code in the image"+child.getName());

        }
        }
        }

        }

        } catch (Exception e) {

        System.out.println("exception occured"+e);


        }



        }

0 个答案:

没有答案