博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
EasyCodeScanner生成二维码
阅读量:4353 次
发布时间:2019-06-07

本文共 1353 字,大约阅读时间需要 4 分钟。

using UnityEngine;

using System.Collections;
using ZXing;
using ZXing.QrCode;
using System;
using System.IO;
public class BarcodeCam : MonoBehaviour
{
public Texture2D encoded;//生成的二维码为Texture2D类型
public string Lastresult;//二维码中所包含的内容信息,我是使用了GUID进行代替
public int count = 5;//生成几个二维码
void Start()
{

encoded = new Texture2D(256, 256);

for (int i = 0; i < count; i++)
{
Guid idKey = Guid.NewGuid();
Lastresult = idKey.ToString();
var textForEncoding = Lastresult;
if (textForEncoding != null)
{
var color32 = Encode(textForEncoding, encoded.width, encoded.height);
encoded.SetPixels32(color32);
encoded.Apply();
byte[] bytes = encoded.EncodeToPNG();//把二维码转成byte数组,然后进行输出保存为png图片就可以保存下来生成好的二维码
if (!Directory.Exists(Application.dataPath + "/AdamBieber"))//创建生成目录,如果不存在则创建目录
{
Directory.CreateDirectory(Application.dataPath + "/AdamBieber");
}
string fileName = Application.dataPath + "/AdamBieber/" + idKey + ".png";
System.IO.File.WriteAllBytes(fileName, bytes);
}
}
}

private static Color32[] Encode(string textForEncoding, int width, int height)
{
var writer = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = new QrCodeEncodingOptions
{
Height = height,
Width = width
}
};
return writer.Write(textForEncoding);
}

void OnGUI()

{
GUI.DrawTexture(new Rect(100, 100, 256, 256), encoded);
}

}

转载于:https://www.cnblogs.com/ZeroMurder/p/5619229.html

你可能感兴趣的文章
12.22
查看>>
新版本的molar mass(uva-1586)明明debug过了,各种测试还是WA真是气死我了
查看>>
gdb(ddd,kdevelop等)调试ZeroIce开发的应用程序,中断信号引起的问题
查看>>
牛股助推器(每股收益率)
查看>>
SpringCloud+feign 基于Springboot2.0 负载均衡
查看>>
【BZOJ5094】硬盘检测 概率
查看>>
mac上n次安装与卸载mysql
查看>>
Python之单元测试——HTMLTestRunner
查看>>
WebNotes(PHP、css、JavaScript等)
查看>>
C++:文件的输入和输出
查看>>
Http协议、Tomcat、servlet
查看>>
Spring Boot (11) mybatis 关联映射
查看>>
macOS 下安装tomcat
查看>>
字符串格式化复习笔记
查看>>
c++ 宏定义调用不定参数的函数
查看>>
动态规划典型例题--背包问题九讲
查看>>
Qt之QHeaderView自定义排序(终极版)
查看>>
python----logging
查看>>
LBP特征 学习笔记
查看>>
与TIME_WAIT相关的几个内核参数修改测试讨论结论
查看>>