title: Read QR Code in Unity with ARKit and ZXing
body: <p>I'm trying to read a QR code with the following libraries:</p>
  
  <ul>
  <li>ARKit</li>
  <li>ZXing</li>
  </ul>
  
  <p>However it doesn't seem to go well. After several hours I still don't manage to read out a decent QR code.
  When debugging i apply the texture to see my result. It looks red because of the Texture Y but other than that it shows the QR code.
  Interpreting the texture doesn't return any data analyzed by ZXing.</p>
  
  <p>This is the following code i'm using for this:</p>
  
  <pre><code>#if UNITY_IOS &amp;&amp; !UNITY_EDITOR
      // Update is called once per frame
      // BETTER: InvokeRepeating
      void Update()
      {
          if (!done) {
              ARTextureHandles handles = arSession.GetARVideoTextureHandles();
              //ARTextureHandles handles = UnityARSessionNativeInterface.GetARSessionNativeInterface().GetARVideoTextureHandles();
              if (handles.IsNull())
              {
                  return;
              }
              if (handles.TextureY != System.IntPtr.Zero) {
                  ReadQRCode (handles.TextureY);
              }
          }
  
  }
  #endif
  
  private void ReadQRCode(System.IntPtr mtlTexPtr)
  {
      Debug.Log("---------------");
      Debug.Log("Scanning...");
  
      Resolution currentResolution = Screen.currentResolution;
  
      tex = (UnityEngine.Texture2D)GameObject.Find("Camera").GetComponent&lt;UnityARVideo&gt;().m_ClearMaterial.GetTexture("_textureCbCr");
  
      tex.UpdateExternalTexture(mtlTexPtr);
  
      try
      {
          if(barCodeReader == null) {
              Debug.Log("Could not find barcorereader");
          }
          if(tex == null) {
              Debug.Log("Could not find texture");
          }
  
          var data = barCodeReader.Decode(tex.GetPixels32(), currentResolution.width, currentResolution.height);
          if (data != null)
          {
              Debug.Log("QR: " + data.Text);
          }
          else
          {
              Debug.Log("NO QR: " + "No QR code detected !");
          }
      }
      catch (Exception e)
      {
          Debug.LogError("Error reading QR");
          Debug.LogError(e.Message);
      }
  }
  </code></pre>