Generate a QR code with some missing pixel

844 Views Asked by At

For a project, we were asked to re-create the same QR code as on a pdf we received.

I managed to do almost the same but I can't find the solution. Here is the QR Code we need to recreate (I've added red arrows).

QR code I have to reproduce

You see there is almost every time a pixel less and in another place a pixel more. Here's my QR Code except that I miss no pixel.

QR code I generated

I'm using boofcv library and here is my code

QrCode qr = new QrCodeEncoder().setError(QrCode.ErrorLevel.M).setMask(QrCodeMaskPattern.M111).setVersion(1).addBytes("E-ALPZNUP").fixate();
    QrCodeGeneratorImage render = new QrCodeGeneratorImage(42);
    render.render(qr);
    BufferedImage buffimage = ConvertBufferedImage.convertTo(render.getGray(),null);

If someone has the same solution with another library I can take it.

2

There are 2 best solutions below

3
On

I know it's not my business to bother about why you have such requirement to generate exactly the same QR code, but my guess is that the 'extra' and 'missing' pixels of the original picture are due to the JPEG encoding of the image. I know it's in PNG, but maybe after generation it was encoded in JPEG and then back to PNG. There's no pattern at all when the pixel appears, so there must be something random or fuzzy which adds it to the first image. Alternatively, it's some kind of signature that they're adding to the original QR to identify that it was legitimately generated by a specific authority.

From reading perspective, they're both exactly the same and both QR codes will provide the same output.

0
On

You can probably try Free Spire.Barcode for Java and the below code:

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import com.spire.barcode.BarCodeGenerator;
import com.spire.barcode.BarCodeType;
import com.spire.barcode.BarcodeSettings;
import com.spire.barcode.QRCodeECL;
import com.sun.javafx.print.Units;

public class QR_Code {

    public static void main(String[] args) throws IOException {

        //create an instance of BarcodeSetteings
        BarcodeSettings settings = new BarcodeSettings();
        //set barcode type
        settings.setType(BarCodeType.QR_CODE);
        //set barcode data
        settings.setData("ABC 123456789");
        //set dispaly text
        settings.setData2D("ABC 123456789");
        //show text on bottom
        settings.setShowTextOnBottom(true);
        //set the border invisible
        settings.hasBorder(false);
        //set width of the barcode module
        settings.setX(2);
        //set the error correction level
        settings.setQRCodeECL(QRCodeECL.M);    
        //create BarCodeGenerator object based on settings
        BarCodeGenerator barCodeGenerator = new BarCodeGenerator(settings);
        //generate image data and store in BufferedImage instance
        BufferedImage bufferedImage = barCodeGenerator.generateImage();
        //save to image
        ImageIO.write(bufferedImage,"png",new File("QR_CODE.png"));
        System.out.println("Complete!");
    }    
}

Code copy from Generate QR Code in Java