Java: не удается декодировать QR-коды с помощью Zxing - PullRequest
0 голосов
/ 25 сентября 2018

Я борюсь с библиотекой Google Zxing Java.Я пытаюсь разобрать несколько QR-кодов, и для некоторых из них это отлично работает.Другие не распознаются, и я не могу сказать, почему.

Вот что я получил до сих пор.

Pom.xml

<dependency>
   <groupId>com.google.zxing</groupId>
   <artifactId>core</artifactId>
   <version>3.3.3</version>
</dependency>
<dependency>
   <groupId>com.google.zxing</groupId>
   <artifactId>javase</artifactId>
   <version>3.3.3</version>
</dependency>

Test.java

public static String decodeQRCode(BufferedImage bufferedImage) throws NotFoundException {
    LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

    MultiFormatReader multiFormatReader = new MultiFormatReader();
    Map<DecodeHintType, Object> hints = new HashMap();
    hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
    hints.put(DecodeHintType.POSSIBLE_FORMATS, Arrays.asList(BarcodeFormat.QR_CODE));
    hints.put(DecodeHintType.CHARACTER_SET, StandardCharsets.UTF_8.name());
    multiFormatReader.setHints(hints);
    Result result = multiFormatReader.decode(bitmap, hints);

    return result.getText();
}

@Test
public void testQrCode() throws IOException, NotFoundException {
    ClassLoader classloader = Thread.currentThread().getContextClassLoader();
    InputStream inputStream = classloader.getResourceAsStream("qrcode.png");
    BufferedImage bufferedImage = ImageIO.read(inputStream);
    String decodedText = decodeQRCode(bufferedImage);
    System.out.println("Decoded text = " + decodedText);
}

QR-код

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...