Unity3d open Local camera scan QR code

Source: Internet
Author: User

First download Zxing.net.0.12.0.0.zip, for http://zxingnet.codeplex.com/.

' Unzip to find the Unity folder and then drop it into Unity project.

Using Unityengine;
Using System.Collections;
Using ZXing;
Using Unityengine.ui;

public class Qrcode:monobehaviour
{
public color32[] data;
private bool Isscan;
Public Rawimage cameratexture;
Public Text Txtqrcode;
Private Webcamtexture webcameratexture;
Private Barcodereader Barcodereader;
Private float timer = 0;

IEnumerator Start ()
{
Barcodereader = new Barcodereader ();
Yield return application.requestuserauthorization (USERAUTHORIZATION.WEBCAM);
if (Application.hasuserauthorization (Userauthorization.webcam))
{
webcamdevice[] devices = webcamtexture.devices;
string devicename = Devices[0].name;
Webcameratexture = new Webcamtexture (DeviceName, 400, 300);
Cameratexture.texture = webcameratexture;
Webcameratexture.play ();
Isscan = true;
}

}


void Update ()
{
if (Isscan)
{
Timer + = Time.deltatime;

if (Timer > 0.5f)//0.5 Second scan
{
Startcoroutine (Scanqrcode ());
Timer = 0;
}
}

}

IEnumerator Scanqrcode ()
{
data = Webcameratexture.getpixels32 ();
DECODEQR (Webcameratexture.width, webcameratexture.height);
Yield return new waitforendofframe ();
}

private void Decodeqr (int width, int height)
{
var br = Barcodereader.decode (data, width, height);
if (br! = NULL)
{
Txtqrcode.text = Br. Text;
Isscan = false;
Webcameratexture.stop ();
}

}

}

Unity3d open Local camera scan QR code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.