3

I have been playing around with zxing over the weekend, and have ran into a problem that I am unable to solve. I am using the working java code example at QR Code encoding and decoding using zxing, and am interested in converting the generated BitMatrix (that houses bits of the qr code) into a byte[] so that I can store the image in an sql lite blob field (and then draw the bar code when I want to). Does anyone know if this is possible. I am not sure where to go from the encoding solution that I have provided. I've looked at http://zxing.org/w/docs/javadoc/com/google/zxing/client/j2se/MatrixToImageWriter.html for a solution, but haven't found any fixes for my problem (I thought maybe accomplish this via MatrixToImageWriter.

Any help is greatly appreciated!

Cheers!

Community
  • 1
  • 1
MRN
  • 193
  • 1
  • 12

1 Answers1

3

BitMatrix has several methods to get its contents, like get() which gets bit by bit or getRow() which gives you a row at a time as a BitArray. You can get the bits and do whatever you want.

Sean Owen
  • 66,182
  • 23
  • 141
  • 173
  • so the idea would be to loop through the BitMatrix, continually adding the rows to the byte[]? Then I could toss this into the database base blob field? – MRN Oct 30 '11 at 20:04
  • Yeah exactly just read off the the bits row by row and build your byte array from those bits. You can do the reverse to reconstruct the matrix. – Sean Owen Oct 30 '11 at 21:19
  • Hey Sean, I seem to be running into another problem. Maybe you can spot it if you're around. – MRN Nov 01 '11 at 05:55
  • What is the question? The Google Group for the project is probably a better place to continue. – Sean Owen Nov 01 '11 at 06:22
  • I figured it out :). It was a slight error in the decoding process that I caught. I'll go ahead and mark this as the best answer. Thanks for your help, Sean! – MRN Nov 01 '11 at 06:55
  • @SeanOwen is there an example of getting a `byte[]` from `BitMatrix`, or has this API changed? I'm also trying to get `byte[]` from `BitMatrix` and not seeing a clear way – Don Cheadle Mar 16 '15 at 15:06