- Home /
Trouble with ZXing QR Scanning
Hi, i'm creating an app in Unity and i would like to set a QR scanner, and one of the best choices i've found to do this is using ZXing Scan with the Vuforia Cam. Ok, but i have a problem with my code. Everytime it red a QR code, opens automatically the link asociated to the QR, but when I come back to the app, it opens it again and again everytime i enter before scanning any code. I tried to set Destroy or a SetActive for the text and the ZXing.Result in the code, but it stop in the line which it gets the link and open the navigator and it donesn't go down in the code. ( Application.OpenURL (data1.Text);)
What i want is that my app can read a code, showing text in the screen, without enter automaticlly in the navigator, and when i come back to the app, be able to read another code, not repeating the same code forever. I think the best way is converting the ZXing.Result into a String, but i don't know how, cause when i use #using UnityEngine.UI, it doesn't works and conflicts with other galleries.
(My code is a mess, i'm sorry, any doubt pls tell me)
using UnityEngine;
using System;
using System.Collections;
using Vuforia;
using System.Threading;
using ZXing;
using ZXing.QrCode;
using ZXing.Common;
[AddComponentMenu("System/VuforiaScanner")]
public class VuforiaScanner : MonoBehaviour
{
private bool cameraInitialized;
public GameObject escena;
public GameObject menu;
private GameObject bg;
public BarcodeReader barCodeReader;
public BarcodeReader barCodeReader2;
void Awake(){
escena = GameObject.Find("ARCamera(Clone)");
menu = GameObject.Find ("Canvas/Cotrolador movimiento/mainmenu");
bg = GameObject.Find ("Canvas/Cotrolador movimiento/backgrounds");
}
void Start()
{
StartCoroutine(InitializeCamera());
}
private IEnumerator InitializeCamera()
{
yield return new WaitForSeconds (1.25f);
var isFrameFormatSet = CameraDevice.Instance.SetFrameFormat (Image.PIXEL_FORMAT.RGB888, true);
Debug.Log (String.Format ("FormatSet : {0}", isFrameFormatSet));
var isAutoFocus = CameraDevice.Instance.SetFocusMode (CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
if (!isAutoFocus) {
CameraDevice.Instance.SetFocusMode (CameraDevice.FocusMode.FOCUS_MODE_NORMAL);
}
Debug.Log (String.Format ("AutoFocus : {0}", isAutoFocus));
cameraInitialized = true;
}
public void Update()
{
if (cameraInitialized)
{
try
{
var cameraFeed = CameraDevice.Instance.GetCameraImage(Image.PIXEL_FORMAT.RGB888);
if (cameraFeed == null)
{
return;
}
barCodeReader = new BarcodeReader();
barCodeReader2 = new BarcodeReader();
var data1 = barCodeReader.Decode(cameraFeed.Pixels, cameraFeed.BufferWidth, cameraFeed.BufferHeight, RGBLuminanceSource.BitmapFormat.RGB24);
if (data1 != null)
{
escena.SetActive (false);
bg.SetActive (true);
menu.SetActive (true);
Application.OpenURL (data1.Text);
data1 = null;
}
}
catch (Exception e)
{
Debug.LogError(e.Message);
}
}
}
}
Your answer
Follow this Question
Related Questions
Creating planes in Unity 1 Answer
Getting number of seconds a user has been in game 2 Answers
Xbox Controller and Unity Buttons UI 0 Answers
Vuforia Target Image scene not appearing in game 0 Answers
[SOLVED] Why is text not appearing? 2 Answers