Writing binary data using zxing

961 views
Skip to first unread message

magnus...@gmail.com

unread,
Feb 25, 2009, 1:00:29 PM2/25/09
to zxing
Hi,

I'd like to write binary data (it's a cryptographic signature) in a QR
or Data Matrix code. Is there any way of doing this using zxing short
of base64 encoding it and writing it as text?

Sean Owen

unread,
Feb 25, 2009, 2:27:54 PM2/25/09
to zxing
Yes, and kind of no.

"Kind of no" in the sense that QR code and Data Matrix both
fundamentally treat their payload as text. QR code's 'byte mode' is
actually supposed to be interpreted as ISO-8859-1 text by default (or
another encoding if so signaled). "Kind of no" in the sense that
readers will invariably attempt to construe the payload as text.

But, if you have a custom reader that is aware of what you're doing --
yes. For example, you can put your custom payload in a "byte mode"
segment in a QR code. When you decode with this library, call
Result.getResultMetadata() on the result. This is a Hashtable. Look up
what is mapped to key ResultMetadataType.BYTE_SEGMENTS. This is a
Vector of byte[], containing the bytes in each byte segment in the
code. This is your payload that you can do with as you like.

magnus...@gmail.com

unread,
Feb 26, 2009, 1:59:21 AM2/26/09
to zxing
Thanks for the quick answer!
Yes, I don't expect anyone but I will ever write a reader for this.
The decoding seems to be easy enough, but I don't understand how to do
the encoding. The com.google.zxing.qrcode.encoder.Encoder class seems
to pick the mode itself. Is there any way of making chooseMode pick
latin1 short of prefixing my data with a non-alphanumeric byte? (which
should work, but isn't documented and feels like cheating ;-) )

Regards
Magnus

Sean Owen

unread,
Feb 26, 2009, 4:11:00 AM2/26/09
to zxing
Yes, you've hit on a reasonable way to force the behavior you need.
The other possibility is simply to open up the code and modify it.

magnus...@gmail.com

unread,
Mar 2, 2009, 7:06:50 AM3/2/09
to zxing
Ok, problem solved. Thank you!

Regards
Magnus
Reply all
Reply to author
Forward
0 new messages