I made two demo applications in C#: the first generates a QR Code which is saved as bmp and the second scans this saved bmp.
The first demo application generates a QR Code via "QRCodeGenerator.CreateQrCode" from a byte array named "dataStream". This byte stream (i.e. dataStream) is equal to { 254, 111, 2, 0, 128, 73, 28, 80, 1, 0, 2, 0, 89, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; and the generated QRCode is obtained by:
var barcode = new ZXingBarcodeImageView
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
WidthRequest = 300,
HeightRequest = 300,
Margin = 10,
};
barcode.BarcodeFormat = ZXing.BarcodeFormat.QR_CODE;
barcode.BarcodeOptions.Hints.Add(ZXing.EncodeHintType.CHARACTER_SET, "UTF-8");
barcode.BarcodeValue = Encoding.UTF8.GetString(dataStream, 0, dataStream.Length);
The second demo application scans this QR Code and produces a byte array which is compared to the one that generated such QR Code. This byte array is obtained by processing the obtained ZXing.Result named "dataQRCode" as such:
byte[] receivedDataStream = System.Text.Encoding. UTF8.GetBytes(dataQRCode.Text);
While I am expecting to obtain that receivedDataStream is equal to dataStream, I obtain that receivedDataStream is equal to {63, 11, 2, 0, 63, 73, 28, 86, 1, 0, 2, 0, 89, 1, 2, ...}.
I did some google and I found this google group and that the issue could be on the encoding part... However, I already specified that the encoding is "UTF-8" in both encoding and decoding.
Anyone knows what I am missing? Can you point me in the right direction, please?
I join the QR Code obtained by the first application.
All the best from the sunny Italy,
Lorenzo
I thought the very same, and I tried the "ISO-8859-1" encoding without success : \.
Definitely, I believe that I am missing something; I attach here the archives of the application demos which are based on ZXing examples (i.e. XFGenBarcode and XFScan), and the updated QRCode. I hope to figure out what I am missing with your help.
Thanks in advance ;)
P.S. I pruned the code, so in order to dump the generated QRCode you should do a print screen, edit it via paint or similar, and save the bmp. Then, load the bmp or the attached one to the camera during emulation.
Fortunately, I found a this question on stack (https://stackoverflow.com/questions/11067723/encoding-and-decoding-byte-with-zxing). Following this idea, the issue seems resolved. Attached, the right QR Code containing { 254, 111, 2, 0, 128, 73, 28, 80, 1, 0, 2, 0, 89, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }.
To summarize: I setted the CHARACTER_SET to ISO-8859-1 in QR Code; set the QR Code text as the byte array encoded as base64; and, decoded the QR Code text as string from base64.