WP7 - Problems with generated QR codes

Oct 11, 2012 at 11:33 PM
Edited Oct 11, 2012 at 11:37 PM

I've tested the library in a WP 7.1 solution and i'm experiencing some odd results. After generating the image and trying to scan it with Bing Vision on my Windows Phone, it will only manage to extract the content when using numbers.When using letters or mixing letters and numbers, Bing Vision will recognize the QR code, but return no content. I've not had problems with Bing Vision not recognizing QR codes in the past, so i'm wondering if i'm doing something wrong?


Example:

 

var writer = new BarcodeWriter
{
    Format = BarcodeFormat.QR_CODE,
    Options = new QrCodeEncodingOptions
    {
        Height = 400,
        Width = 400,
    }
};
QrCode = writer.Write("12345");  // works
QrCode = writer.Write("12345a"); // doesn't work
QrCode = writer.Write("abcde");  // doesn't work
Oct 12, 2012 at 8:40 AM

Update: Seems like Bing Vision is more picky than some other apps after all. Worked on the Samsung Galaxy S3 and WP with i-nigma app with much more content in the code.

Coordinator
Oct 12, 2012 at 8:11 PM

Mainly it isn't a Bing Vision issue.

It's more a character set issue. The default character set for QR Code is ISO-8859-1. But that codepage isn't supported in silverlight and windows phone out of the box. So I set the character set to UTF-8. That leads to a so-called ECI segment ("Extended Channel Interpretations" 5.3.1.1 of ISO 18004) within the QR Code. Some scanners have trouble with such control segments. The character set is only used if byte mode is used. If you only have digits in your content the numeric mode without the ECI segment is used.

To be clear:

  • 12345 -> encoding mode is numeric without ECI --> QR code should work with every scanner
  • 12345a -> encoding mode is byte because of non-numeric character and UTF-8 character set --> some scanner will have trouble, don't scan the code or they crash (I found one scanner on my iPhone which crashs, 2 apps succeeded)

There are two solutions:

  1. all scanner should support the ECI segment (hard to realize, I know)
  2. I will add ISO-8859-1 character set to ZXing.Net for Silverlight and Windows Phone (possible, but I have no idea at the moment)
Coordinator
Oct 12, 2012 at 8:29 PM

It seems to me that I was wrong.

ISO-8859-1 is supported by Windows Phone. I will change the code so that it will generate QR code without ECI segment.
It will then support the CHARACTER_SET encoding hint. An app can then set QrCodeEncodingOptions.CharacterSet to a different one than ISO-8859-1.

Oct 14, 2012 at 10:54 AM

Thanks for the replies and taking the time to come up with a solution :)

Jan 3, 2013 at 11:58 AM

 

micjahn wrote:

It seems to me that I was wrong.

ISO-8859-1 is supported by Windows Phone. I will change the code so that it will generate QR code without ECI segment.

It will then support the CHARACTER_SET encoding hint. An app can then set QrCodeEncodingOptions.CharacterSet to a different one than ISO-8859-1.

 

Hi,

I tried your solution to use UTF-8 encoding on windows phone 7.1 and win rt, but I have problems with Bing Vision recognizing the QR codes(empty message). I checked the zxing online generator at http://zxing.appspot.com/generator/ and i was able to generate utf-8 qr codes that my WP7/WP8 devices could recognize, then I checked both qr codes with the zxing online decoder and it recognized both qr codes but with different raw bytes ...

 

So my generated barcode with "abcd" content gives the following result with the online decoder

Raw text

abcd

Raw bytes

71 a4 04 61 62 63 64 00 ec 11 ec 11 ec 11 ec 11 ec 11 ec ec 11 ec

Barcode format

QR_CODE

Parsed Result Type

TEXT

Parsed Result

abcd

Result from qr code generated with zxing online generator (http://chart.apis.google.com/chart?cht=qr&chs=350x350&chld=L&choe=UTF-8&chl=abcd):

Raw text

abcd

Raw bytes

40 46 16 26 36 40 ec 11 ec 11 ec 11 ec 11 ec 11 ec 11 ec ec 11 ec

Barcode format

QR_CODE

Parsed Result Type

TEXT

Parsed Result

abcd

 

Any ideas what is the problem or how can I fix it? I want to encode my qr codes as utf-8 because ISO-8859-1 doesn't have the Hungarian(öüóőúéáűí) accent characters I need.

 

I'm using the following code to generate my qr codes :

var writer = new BarcodeWriter

            {

               Format = BarcodeFormat.QR_CODE,

               Options = new QrCodeEncodingOptions

               {

                   Height = 400,

                   Width = 400,

                   CharacterSet = "UTF-8",

 

               }

            };           

        var writeableBitmapEx = writer.Write(content);

Jan 3, 2013 at 2:54 PM

I managed to fix my issue for now, I don't know if this is a correct solution but it works for the WP7/8(Bing Vision) and QR Droid readers I tried.
Appending the ECI segment for UTF-8 doesn't work for Bing Vision but UTF-8 without ECI segment works just fine on WP8 reader, so I added a new EncodeHintType 

  /// <summary>
  /// Don't append ECI segment.
  /// type: <see cref="System.Boolean" />
  /// </summary>
  DISABLE_ECI,
and the following line to the ZXing.QrCode.Internal.Encoder class in the Encode method

if ( hints != null && hints.ContainsKey(EncodeHintType.DISABLE_ECI) && (bool)hints[EncodeHintType.DISABLE_ECI]) generateECI = false; this way I can control how to generate the code.

Please let me know if there are any better solutions.

Coordinator
Jan 3, 2013 at 9:32 PM

I don't have a better solution at the moment. In my opinion the correct solution would be that every reader supports ECI segments correctly.

As I understand the specification of QR Codes you have to put an ECI segment in front of the content if you don't use the default ISO-8859-1 encoding.
Maybe I'm wrong. There are different versions of the specification.

I played a little around with your data and the command line encoder from the original java-based zxing project.
That encoder generates exactly the same image like my ported code for every combination of your content and the encoding ISO-8859-1 and UTF-8.

At the moment I have no idea what the correct way is. Perhaps I will add your modification to zxing.net.

Jan 3, 2013 at 10:29 PM

Yeah but I don't think that will ever happen... :s , Bing Vision works differently even on WP7.5 and WP8, I tested with both devices and WP7 is not able to decode Hungarian accent properly while WP8 does.

I also checked the online decoder with my version of the generated QR code(with disabled ECI segment) the raw bytes are the same as the online zxing encoder.

Raw text abcd
Raw bytes 40 46 16 26 36 40 ec 11 ec 11 ec 11 ec 11 ec 11 ec 11 ec ec 11 ec
Barcode format QR_CODE
Parsed Result Type TEXT
Parsed Result abcd

and one more change for convenience in the QrCodeEncodingOptions class :)

      /// <summary>
      /// Explicitly disables ECI segment when generating QR Code
      /// </summary>
      public bool DisableECI
      {
          get
          {
              if (Hints.ContainsKey(EncodeHintType.DISABLE_ECI))
              {
                  return (bool)Hints[EncodeHintType.DISABLE_ECI];
              }
              return false;
          }
          set
          {                   
              Hints[EncodeHintType.DISABLE_ECI] = value;          
          }
      }

 

 

Coordinator
Jan 8, 2013 at 8:41 PM

I added your changes to repository. Thanks.