Unity识别二维码功能

using UnityEngine;
using System.Collections;
//using ZXing;
//using ZXing.QrCode;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class QRcode : MonoBehaviour
{
    public GameObject rImage;
    public GameObject musicRawImage;
    public AudioSource AudioS;
    public AudioClip[] AudioC;
    public Text Text;
    public Text MusicNameText;
    //摄像头实时显示的画面
    private WebCamTexture m_webCameraTexture;
    //申请一个读取二维码的变量
    private BarcodeReader m_barcodeRender = new BarcodeReader();


    //多久检索一次二维码
    private float m_delayTime = 3f;

    public RawImage m_cameraTexture;

    private void Awake()
    {
        rImage.SetActive(true);
        musicRawImage.SetActive(false);
    }

    void Start()
    {
        //调用摄像头并将画面显示在屏幕RawImage上
        WebCamDevice[] tDevices = WebCamTexture.devices; //获取所有摄像头
        string tDeviceName = tDevices[0].name; //获取第一个摄像头,用第一个摄像头的画面生成图片信息
        m_webCameraTexture = new WebCamTexture(tDeviceName, 400, 300); //名字,宽,高
        m_cameraTexture.texture = m_webCameraTexture; //赋值图片信息
        m_webCameraTexture.Play(); //开始实时显示
        InvokeRepeating("CheckQRCode", 0, m_delayTime);
    }

    /// <summary>
    /// 检索二维码方法
    /// </summary>
    void CheckQRCode()
    {
        //存储摄像头画面信息贴图转换的颜色数组
        Color32[] m_colorData = m_webCameraTexture.GetPixels32();

        //将画面中的二维码信息检索出来
        var tResult = m_barcodeRender.Decode(m_colorData, m_webCameraTexture.width, m_webCameraTexture.height);
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值