Skip to content

Unable to parse a QR code that was generated from ZXing itself after 110ef9e #1976

@jabagawee

Description

@jabagawee

In response to #1567, ZXing added 110ef9e. However, this has caused ZXing to fail to decode images that it itself has created. I have attached a minimal repro below. The problem may lie in FinderPatternFinder::find, as it seems to believe that two of the three finder patterns in the image only have a count of 1.

package com.google.zxing.client.j2se;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.QRCodeWriter;
import org.junit.Assert;
import org.junit.Test;

import java.awt.image.BufferedImage;
import java.util.UUID;

public class QrCodeRoundTripTestCase extends Assert {
  @Test
  public void testRoundTrip() throws Exception {
    String payload = UUID.randomUUID().toString();

    QRCodeWriter writer = new QRCodeWriter();
    BitMatrix matrix = writer.encode(payload, BarcodeFormat.QR_CODE, 0, 0);
    BufferedImage image = MatrixToImageWriter.toBufferedImage(matrix);

    BufferedImageLuminanceSource source = new BufferedImageLuminanceSource(image);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    MultiFormatReader reader = new MultiFormatReader();

    assertEquals(reader.decode(bitmap).getText(), payload);
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions