生成和识别二维码U3d
2016-02-24 10:22
337 查看
转:http://www.manew.com/thread-47945-1-1.html?_dsign=3548f138
工作繁忙,很久没有更新,略表歉意。关于二维码的生成和识别网上泛泛看了一些,ZXing用的比较多。
ZXing的官网是http://zxingnet.codeplex.com/,它在github有源码,有兴趣的可以自己翻翻看看。
整体代码还是比较简单,为了方便,我识别直接用了生成的二维码,有需求的可以换成从摄像头获取。
工作繁忙,很久没有更新,略表歉意。关于二维码的生成和识别网上泛泛看了一些,ZXing用的比较多。
ZXing的官网是http://zxingnet.codeplex.com/,它在github有源码,有兴趣的可以自己翻翻看看。
publicclass GenerateQRCode : MonoBehaviour { publicTexture2D _texture; publicstring content; Color32[] webCameraTextureData; privateBarcodeReader barcodeReader; voidStart() { _texture = newTexture2D(256, 256); content = "http://www.baidu.com"; barcodeReader = newBarcodeReader(); Generateimages(); Recognition(); } //生成图片 voidGenerateimages() { var textForEncoding = content; if(textForEncoding != null) { var color32 = Encode(textForEncoding, _texture.width, _texture.height); _texture.SetPixels32(color32); _texture.Apply(); //赋值给webCameraTextureData用于识别 webCameraTextureData = color32; } } //生成二维码信息 privatestatic Color32[] Encode(stringtextForEncoding, intwidth, intheight) { var writer = newBarcodeWriter { Format = BarcodeFormat.QR_CODE, Options = newQrCodeEncodingOptions { Height = height, Width = width } }; returnwriter.Write(textForEncoding); } voidOnGUI() { GUI.DrawTexture(newRect(0, 0, 256, 256), _texture); } //识别二维码 publicvoid Recognition() { var data = barcodeReader.Decode(webCameraTextureData, _texture.width, _texture.height); switch(data.BarcodeFormat) { caseBarcodeFormat.QR_CODE: break; } Debug.Log(data); } }
整体代码还是比较简单,为了方便,我识别直接用了生成的二维码,有需求的可以换成从摄像头获取。
相关文章推荐
- curl交叉编译
- ADO编程笔记-记录遇到的问题
- 《时间同步介绍及实战配置——介绍定时任务及简单配置》
- 文本框输入测试用例
- MVC———用自定义扩展类实现验证
- c语言入门之项目3.7——用for循环输出一个等腰直角三角形
- Example #1 Serializing a single value with WDDX
- 23. gicqd
- Socket的使用
- Restful形式接口文档生成之Swagger与SpringMVC整合手记
- 存储过程定位问题
- visual studio 2013 error: Page '312e8a59-2712-48a1-863e-0ef4e67961fc' not found.
- 22. ggv
- Git 学习笔记(二)
- memcache命令说明
- 2016年1月“.中国”域名总量创新高 超过51.7万
- 网络库(1):libevent相关
- 238. Product of Array Except Self
- Wijmo5 Flexgrid基础教程:增加和删除
- Caffe: solver及其配置