Unity生成二维码功能
2017-01-07 20:05
483 查看
当时在做的时候,找了好多dll,最好找到这个dll, 什么都不说啦!
public Texture2D encoded;//生成的二维码为Texture2D类型
public string Lastresult;//二维码中所包含的内容信息,我是使用了GUID进行代替
public int count = 1;//生成几个二维码
void Start ()
{
encoded = new Texture2D(256, 256);
for (int i = 0; i < count; i++)
{
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/" + textForEncoding + ".png";
System.IO.File.WriteAllBytes(fileName, bytes);
}
}
}
private static Color32[] Encode(string textForEncoding, int width, int height)
{
Dictionary<EncodeHintType, object> hints = new Dictionary<EncodeHintType, object>();
hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8"); //默认的编码不支持中文,将输入内容的编码格式
var encoder = new QRCodeWriter
{
};
var writer = new BarcodeWriter
{
//Format = BarcodeFormat.QR_CODE,
//Options = new QrCodeEncodingOptions
//{
// Height = height,
// Width = width,
//},
Encoder = encoder
};
var bitMatrix = writer.Encoder.encode(textForEncoding, BarcodeFormat.QR_CODE, width, height, hints);
return writer.Write(bitMatrix);
}
dll的百度云盘地址:链接: http://pan.baidu.com/s/1pLavJmz 密码: wqyb
public Texture2D encoded;//生成的二维码为Texture2D类型
public string Lastresult;//二维码中所包含的内容信息,我是使用了GUID进行代替
public int count = 1;//生成几个二维码
void Start ()
{
encoded = new Texture2D(256, 256);
for (int i = 0; i < count; i++)
{
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/" + textForEncoding + ".png";
System.IO.File.WriteAllBytes(fileName, bytes);
}
}
}
private static Color32[] Encode(string textForEncoding, int width, int height)
{
Dictionary<EncodeHintType, object> hints = new Dictionary<EncodeHintType, object>();
hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8"); //默认的编码不支持中文,将输入内容的编码格式
var encoder = new QRCodeWriter
{
};
var writer = new BarcodeWriter
{
//Format = BarcodeFormat.QR_CODE,
//Options = new QrCodeEncodingOptions
//{
// Height = height,
// Width = width,
//},
Encoder = encoder
};
var bitMatrix = writer.Encoder.encode(textForEncoding, BarcodeFormat.QR_CODE, width, height, hints);
return writer.Write(bitMatrix);
}
dll的百度云盘地址:链接: http://pan.baidu.com/s/1pLavJmz 密码: wqyb
相关文章推荐
- Unity结合ZXing生成二维码并保存
- C#利用zxing.net生成二维码和条形码并实现打印的功能
- 二维码的功能、特点及使用Java生成带logo的二维码
- 安卓实现二维码生成和扫描功能,扫描支持直接拍照扫码和相册图片扫码,还加了照明功能
- Android高级控件(三)—— 使用Google ZXing实现二维码的扫描和生成相关功能体系
- OpenJWeb新增二维码图片生成功能
- [置顶] Android用Zxing扫二维码/生成二维码功能
- C#利用Zxing.net生成二维码和条形码并实现打印的功能
- Android高级控件(三)—— 使用Google ZXing实现二维码的扫描和生成相关功能体系
- Java生成二维码可添加logo和文字功能
- 生成二维码功能
- 几行代码搞定java生成解析二维码功能
- 生成条形码和二维码并实现打印的功能
- Android平台生成二维码并实现扫描 & 识别功能
- 在Unity中生成二维码
- php实现生成二维码功能
- Android开发扫描和生成二维码功能
- Unity二维码识别和生成二维码
- 【Android】Android实现扫描、生成二维码的功能
- 使用JS 插件qrcode.js生成二维码功能