美文网首页
Unity3d 打开本地摄像头扫描二维码

Unity3d 打开本地摄像头扫描二维码

作者: Nmao | 来源:发表于2017-11-20 11:58 被阅读0次

首先 下载ZXing.Net.0.12.0.0.zip,下载地址为http://zxingnet.codeplex.com/。

’解压找到unity文件夹,然后将其放到unity工程。

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秒扫描一次

{

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();

}

}

}

注意::::http://www.cnblogs.com/laugher/p/5757759.html

相关文章

  • Unity3d 打开本地摄像头扫描二维码

    首先 下载ZXing.Net.0.12.0.0.zip,下载地址为http://zxingnet.codeplex...

  • iOS 11 碎碎念

    相机支持扫描二维码 你的摄像头可自动侦测到镜头画面中的二维码。扫描之后,可立即打开相关网站或 app。你甚至还可以...

  • macOS swiftUI之二维码扫描(AVFoundation

    需求:用macOS的摄像头作为二维码扫描器扫描二维码获取信息基本流程:1、创建session(捕捉会话) let ...

  • H5混合开发二维码扫描以及调用本地摄像头

    今天主管给了我个需求,说要用混合开发,用H5调用本地摄像头进行扫描二维码,我之前有做过原生安卓的二维码扫一扫,主要...

  • QRCode-扫描二维码-识别图中二维码

    支持:打开相机扫描识别二维码、打开相册识别图中二维码、打开手电筒。 对扫描进行了简单的优化:原生的扫描快,但是识别...

  • 二维码扫描识别

    首先给出本文小Deme二维码的识别包括了两种方法,一种是打开摄像头扫描,一种是扫描相册的图片。没事的时候写了小de...

  • ios二维码生成扫描

    ios二维码生成 根据CIImage生成指定大小的UIImage 扫描 扫描前需要申请调用摄像头的权限 具体代码见...

  • 二维码-ZBar

    ZBar ZBar 是款桌面电脑用条形码/二维码扫描工具,支持摄像头及图片扫描,支持多平台包括 iPhone 手机...

  • (OC 初级笔记)本地读取二维码

    接力上一篇扫描本地二维码的简文. 这次为大家介绍的是本地读取二维码的基本方法, 代码少, 相对easy.2.本地读...

  • 二维码扫码采集与相册二维码提取 - iOS

    二维码扫码和相册二维码提取的方法在原生系统 AVFoundation 的 SDK 中提供了摄像头设备扫描捕获和检测...

网友评论

      本文标题:Unity3d 打开本地摄像头扫描二维码

      本文链接:https://www.haomeiwen.com/subject/irqvvxtx.html