问题
Does anybody know if there is a way to get the raw binary data of a QR code using the android vision API ? The QR codes I am reading have binary data (including NUL characters) in them but are built with 8 bit encoding so the full binary data block is there. The Barcode object returned very helpfully has the string "Unknown encoding" in the rawValue field, instead of my binary data ? Thanks for any ideas!
回答1:
To answer my own question, it seems both the android vision and zxing libraries convert the bytes to utf8 if the encoding is not specified in the QR code (or left at default). I thought that the default encoding was ISO8859-1 but the libraries don't assume that.
The QR code was generated using libqrencode in linux. Setting the ECI header to 1 in the QR code when generated causes the android libraries to preserve the binary data.
So, reading the byte array with barcodes.valueAt(0).displayValue.getBytes("iso-8859-1");
returns the exact encoded bytes.
来源:https://stackoverflow.com/questions/38398840/qr-codes-raw-binary-data