-
using System.Collections;
-
using System.Collections.Generic;
-
using UnityEngine;
-
using ZXing;
-
using UnityEngine.UI;
-
/// <summary>
-
/// 二维码扫描识别功能
-
/// </summary>
-
public class TestQRCodeScanning : MonoBehaviour {
-
-
[
-
public RawImage cameraTexture;//摄像机映射显示区域
-
-
private WebCamTexture webCamTexture;//摄像机映射纹理
-
public Text text;//用来显示扫描信息
-
//二维码识别类
-
BarcodeReader barcodeReader;//库文件的对象(二维码信息保存的地方)
-
-
/// <summary>
-
/// 开启摄像机和准备工作
-
/// </summary>
-
void DeviceInit()
-
{
-
-
-
//1、获取所有摄像机硬件
-
WebCamDevice[] devices = WebCamTexture.devices;
-
//2、获取第一个摄像机硬件的名称
-
string deviceName = devices[0].name;//手机后置摄像机
-
//3、创建实例化一个摄像机显示区域
-
webCamTexture = new WebCamTexture(deviceName, 400, 300);
-
//4、显示的图片信息
-
cameraTexture.texture = webCamTexture;
-
//5、打开摄像机运行识别
-
webCamTexture.Play();
-
-
//6、实例化识别二维码信息存储对象
-
barcodeReader = new BarcodeReader();
-
}
-
-
Color32[] data;//二维码图片信息以像素点颜色信息数组存放
-
-
/// <summary>
-
/// 识别摄像机图片中的二维码信息
-
/// 打印二维码识别到的信息
-
/// </summary>
-
void ScanQRCode()
-
{
-
//7、获取摄像机画面的像素颜色数组信息
-
data = webCamTexture.GetPixels32();
-
//8、获取图片中的二维码信息
-
Result result = barcodeReader.Decode(data,webCamTexture.width,webCamTexture.height);
-
//如果获取到二维码信息了,打印出来
-
if (result!=null)
-
{
-
Debug.Log(result.Text);//===》==》===》 这是从二维码识别出来的信息
-
text.text = result.Text;//显示扫描信息
-
-
//扫描成功之后的处理
-
IsScanning = false;
-
webCamTexture.Stop();
-
}
-
}
-
-
-
/// <summary>
-
/// Start 初始化函数
-
/// </summary>
-
private void Start()
-
{
-
scanningButton.onClick.AddListener(ScanningButtonClick);
-
}
-
-
-
bool IsScanning = false;
-
float interval = 3;//扫描识别时间间隔
-
[
-
void ScanningButtonClick()
-
{
-
DeviceInit();
-
IsScanning = true;
-
}
-
-
private void Update()
-
{
-
if (IsScanning)
-
{
-
//每隔一段时间进行一次识别二维码信息
-
interval += Time.deltaTime;
-
if (interval>=3)
-
{
-
interval = 0;
-
ScanQRCode();//开始扫描
-
}
-
}
-
}
-
}
ZXing:https://archive.codeplex.com/?p=zxingnet
下载之后把zxing.unity.dll拷贝到Unity的Plugins文件夹下,
zxing.unity.dll下载之后的位置找到UnityDemo/Assets下
-
using System.Collections;
-
using System.Collections.Generic;
-
using UnityEngine;
-
using UnityEngine.UI;
-
using ZXing;
-
//二维码的生成
-
public class TestQRCodeDraw : MonoBehaviour {
-
-
[
-
public RawImage QRCode;
-
//二维码绘制类
-
BarcodeWriter barcodeWriter;
-
[
-
/// <summary>
-
/// 将制定字符串信息转换成二维码图片信息
-
/// </summary>
-
/// <param name="formatStr">要生产二维码的字符串信息</param>
-
/// <param name="width">二维码的宽度</param>
-
/// <param name="height">二维码的高度</param>
-
/// <returns>返回二维码图片的颜色数组信息</returns>
-
Color32[] GeneQRCode(string formatStr,int width,int height)
-
{
-
//绘制二维码前进行一些设置
-
ZXing.QrCode.QrCodeEncodingOptions options =
-
new ZXing.QrCode.QrCodeEncodingOptions();
-
//设置字符串转换格式,确保字符串信息保持正确
-
options.CharacterSet = "UTF-8";
-
//设置绘制区域的宽度和高度的像素值
-
options.Width = width;
-
options.Height = height;
-
//设置二维码边缘留白宽度(值越大留白宽度大,二维码就减小)
-
options.Margin = 1;
-
-
//实例化字符串绘制二维码工具
-
barcodeWriter = new BarcodeWriter {Format=BarcodeFormat.QR_CODE,Options=options };
-
//进行二维码绘制并进行返回图片的颜色数组信息
-
return barcodeWriter.Write(formatStr);https://www.cnblogs.com/p199543H/articles/12977982.html
https://www.cnblogs.com/webdesigner/articles/12977983.html
https://www.cnblogs.com/annie_229/articles/12977984.html
https://www.cnblogs.com/zzll123/articles/12977985.html
https://www.cnblogs.com/yilx/articles/12977986.html
https://www.cnblogs.com/yilx/articles/12977988.html
https://www.cnblogs.com/webdesigner/articles/12977991.html
https://www.cnblogs.com/yilx/articles/12977992.html
https://www.cnblogs.com/zzll123/articles/12977993.html
https://www.cnblogs.com/annie_229/articles/12977995.html
https://www.cnblogs.com/yilx/articles/12977996.html
https://www.cnblogs.com/webdesigner/articles/12977997.html
https://www.cnblogs.com/webdesigner/articles/12978002.html
https://www.cnblogs.com/webdesigner/articles/12978006.html
https://www.cnblogs.com/webdesigner/articles/12978010.html
https://www.cnblogs.com/webdesigner/articles/12978016.html
https://www.cnblogs.com/webdesigner/articles/12978018.html
https://www.cnblogs.com/webdesigner/articles/12978022.html
https://www.cnblogs.com/zzll123/articles/12978023.html
https://www.cnblogs.com/annie_229/articles/12978024.html
https://www.cnblogs.com/annie_229/articles/12978030.html
https://www.cnblogs.com/annie_229/articles/12978035.html
https://www.cnblogs.com/annie_229/articles/12978040.html
https://www.cnblogs.com/annie_229/articles/12978044.html
https://www.cnblogs.com/annie_229/articles/12978048.html
https://www.cnblogs.com/annie_229/articles/12978053.html
https://www.cnblogs.com/annie_229/articles/12978056.html
www.cnblogs.com/annie_229/articles/12977868.html
www.cnblogs.com/annie_229/articles/12977863.html
www.cnblogs.com/annie_229/articles/12977858.html
www.cnblogs.com/annie_229/articles/12977853.html
www.cnblogs.com/annie_229/articles/12977846.html
www.cnblogs.com/annie_229/articles/12977840.html
www.cnblogs.com/annie_229/articles/12977837.html
www.cnblogs.com/annie_229/articles/12977921.html
www.cnblogs.com/annie_229/articles/12977915.html
www.cnblogs.com/annie_229/articles/12977910.html
www.cnblogs.com/annie_229/articles/12977905.html
www.cnblogs.com/annie_229/articles/12977899.html
www.cnblogs.com/annie_229/articles/12977895.html
www.cnblogs.com/annie_229/articles/12977888.html
www.cnblogs.com/annie_229/articles/12977883.html
www.cnblogs.com/annie_229/articles/12977878.html
www.cnblogs.com/annie_229/articles/12977874.html
www.cnblogs.com/zzll123/articles/12977929.html
www.cnblogs.com/zzll123/articles/12977923.html
www.cnblogs.com/zzll123/articles/12977916.html
www.cnblogs.com/zzll123/articles/12977911.html
www.cnblogs.com/zzll123/articles/12977908.html
www.cnblogs.com/zzll123/articles/12977902.html
www.cnblogs.com/zzll123/articles/12977893.html
www.cnblogs.com/zzll123/articles/12977886.html
www.cnblogs.com/zzll123/articles/12977881.html
www.cnblogs.com/zzll123/articles/12977876.html
www.cnblogs.com/zzll123/articles/12977873.html
www.cnblogs.com/zzll123/articles/12977869.html
www.cnblogs.com/zzll123/articles/12977864.html
www.cnblogs.com/zzll123/articles/12977859.html
www.cnblogs.com/zzll123/articles/12977854.html
www.cnblogs.com/zzll123/articles/12977848.html
www.cnblogs.com/zzll123/articles/12977844.html
www.cnblogs.com/yilx/articles/12977871.html
www.cnblogs.com/yilx/articles/12977867.html
www.cnblogs.com/yilx/articles/12977861.html
www.cnblogs.com/yilx/articles/12977856.html
www.cnblogs.com/yilx/articles/12977851.html
www.cnblogs.com/yilx/articles/12977845.html
www.cnblogs.com/yilx/articles/12977841.html
www.cnblogs.com/yilx/articles/12977931.html
www.cnblogs.com/yilx/articles/12977924.html
www.cnblogs.com/yilx/articles/12977918.html
www.cnblogs.com/yilx/articles/12977912.html
www.cnblogs.com/yilx/articles/12977906.html
www.cnblogs.com/yilx/articles/12977901.html
www.cnblogs.com/yilx/articles/12977896.html
www.cnblogs.com/yilx/articles/12977887.html
www.cnblogs.com/yilx/articles/12977882.html
www.cnblogs.com/yilx/articles/12977877.html
www.cnblogs.com/p199543H/articles/12977935.html
www.cnblogs.com/p199543H/articles/12977930.html
www.cnblogs.com/p199543H/articles/12977925.html
www.cnblogs.com/p199543H/articles/12977917.html
www.cnblogs.com/p199543H/articles/12977913.html
www.cnblogs.com/p199543H/articles/12977909.html
www.cnblogs.com/p199543H/articles/12977898.html
www.cnblogs.com/p199543H/articles/12977894.html
www.cnblogs.com/p199543H/articles/12977891.html
www.cnblogs.com/p199543H/articles/12977884.html
www.cnblogs.com/p199543H/articles/12977880.html
www.cnblogs.com/p199543H/articles/12977875.html
www.cnblogs.com/p199543H/articles/12977866.html
www.cnblogs.com/p199543H/articles/12977862.html
www.cnblogs.com/p199543H/articles/12977857.html
www.cnblogs.com/p199543H/articles/12977852.html
www.cnblogs.com/p199543H/articles/12977847.html
www.cnblogs.com/p199543H/articles/12977842.html
www.cnblogs.com/p199543H/articles/12977838.html
www.cnblogs.com/p199543H/articles/12977835.html
www.cnblogs.com/p199543H/articles/12977834.html
www.cnblogs.com/p199543H/articles/12977833.html
www.cnblogs.com/webdesigner/articles/12977932.html
www.cnblogs.com/webdesigner/articles/12977927.html
www.cnblogs.com/webdesigner/articles/12977920.html
www.cnblogs.com/webdesigner/articles/12977914.html
www.cnblogs.com/webdesigner/articles/12977907.html
www.cnblogs.com/webdesigner/articles/12977900.html
www.cnblogs.com/webdesigner/articles/12977892.html
www.cnblogs.com/webdesigner/articles/12977885.html
www.cnblogs.com/webdesigner/articles/12977879.html
www.cnblogs.com/webdesigner/articles/12977872.html
www.cnblogs.com/webdesigner/articles/12977860.html
www.cnblogs.com/webdesigner/articles/12977855.html
www.cnblogs.com/webdesigner/articles/12977850.html
www.cnblogs.com/webdesigner/articles/12977843.html
www.cnblogs.com/webdesigner/articles/12977839.html
www.cnblogs.com/webdesigner/articles/12977836.html
https://www.cnblogs.com/b197594K/articles/12977957.html
https://www.cnblogs.com/b197594K/articles/12977958.html
https://www.cnblogs.com/b197594K/articles/12977959.html
https://www.cnblogs.com/b197594K/articles/12977960.html
https://www.cnblogs.com/b197594K/articles/12977961.html
https://www.cnblogs.com/b197594K/articles/12977962.html
https://www.cnblogs.com/b197594K/articles/12977963.html
https://www.cnblogs.com/b197594K/articles/12977964.html
https://www.cnblogs.com/b197594K/articles/12977966.html
https://www.cnblogs.com/b197594K/articles/12977968.html
https://www.cnblogs.com/b197594K/articles/12977974.html
https://www.cnblogs.com/b197594K/articles/12977976.html
https://www.cnblogs.com/b197594K/articles/12977977.html
https://www.cnblogs.com/b197594K/articles/12977999.html
https://www.cnblogs.com/b197594K/articles/12978004.html
https://www.cnblogs.com/b197594K/articles/12978009.html
https://www.cnblogs.com/b197594K/articles/12978014.html
https://www.cnblogs.com/b197594K/articles/12978020.html
https://www.cnblogs.com/b197594K/articles/12978027.html
https://www.cnblogs.com/b197594K/articles/12978031.html
https://www.cnblogs.com/b197594K/articles/12978037.html
https://www.cnblogs.com/b197594K/articles/12978042.html
https://www.cnblogs.com/b197594K/articles/12978046.html
https://www.cnblogs.com/b197594K/articles/12978050.html
https://www.cnblogs.com/b197594K/articles/12978054.html
https://www.cnblogs.com/b197594K/articles/12978057.html
https://www.cnblogs.com/b197594K/articles/12978059.html
https://www.cnblogs.com/b197594K/articles/12978060.html
https://www.cnblogs.com/b197594K/articles/12978061.html
https://www.cnblogs.com/b197594K/articles/12978063.html
https://www.cnblogs.com/b197594K/articles/12978064.html -