Search code examples
javaqr-codezxing

Convert BitMatrix output from QRCodeWriter to byte array?


I have an API which the frontend (PHP) calls to generate a QR code. The QR code is sent back as a byte array (byte[]). Currently we're using a paid library which can render the qr code to an OutputStream, like a ByteArrayOutputStream. But this library doesn't support some UTF-8 characters which is causing a problem for us. Going through the QR code generation process for ZXing we've noticed that the character set can be specified in a hashtable before encoding containing the QR code.

We would like to change the existing functionality as little as possible. Hence was wondering if it was possible to convert the BitMatrix output from the QRCodeWriter.encode method into a byte array?


Solution

  • You can find some sample code of reading and converting a BitMatrix by looking at the class com.google.zxing.client.j2se.MatrixToImageWriter (file on github)