二維碼的生成

  關於二維碼的生成細節和原理,可以參考:http://blog.csdn.net/zy799894671/article/details/19983041#:
可以參考我的上一篇博文來學習二維碼的製作;
這裏我就直接上代碼了:
/// <summary>
/// write by 52cwalk,if you have some question ,please contract lycwalk@gmail.com
/// </summary>
/// using UnityEngine;
using System.Collections;
using System.Collections.Generic;using ZXing;
using ZXing.QrCode;
using ZXing.QrCode.Internal;
using ZXing.Common;public class QRCodeEncodeController : MonoBehaviour {private Texture2D m_EncodedTex;public int e_QRCodeWidth;public int e_QRCodeHeight;public delegate void QREncodeFinished(Texture2D tex);  public event QREncodeFinished e_QREncodeFinished;    //定義事件BitMatrix byteMatrix;void Start (){int targetWidth = Mathf.Min(e_QRCodeWidth,e_QRCodeHeight);targetWidth = Mathf.Clamp (targetWidth, 128, 1024);e_QRCodeWidth = e_QRCodeHeight = targetWidth;m_EncodedTex = new Texture2D(e_QRCodeWidth, e_QRCodeHeight);}void Update (){}/// <summary>/// Encode the specified string ./// </summary>/// <param name="valueStr"> content string.</param>public void Encode(string valueStr){// var writer = new QRCodeWriter();var writer = new MultiFormatWriter();Dictionary<EncodeHintType, object> hints = new Dictionary<EncodeHintType, object>();  //set the code typehints.Add(EncodeHintType.CHARACTER_SET, "UTF-8");  byteMatrix = writer.encode( valueStr, BarcodeFormat.QR_CODE, e_QRCodeWidth, e_QRCodeHeight,hints); //writer1.encode("ddd",BarcodeFormat.for (int i =0; i!= e_QRCodeWidth; i++) {for(int j = 0;j!= e_QRCodeHeight;j++){if(byteMatrix[i,j]){m_EncodedTex.SetPixel(i,j,Color.black);}else{m_EncodedTex.SetPixel(i,j,Color.white);}}}///rotation the image Color32[] pixels = m_EncodedTex.GetPixels32();pixels = RotateMatrixByClockwise(pixels, m_EncodedTex.width);m_EncodedTex.SetPixels32(pixels); m_EncodedTex.Apply ();e_QREncodeFinished (m_EncodedTex);   //編譯完成觸發事件,在其他類中添加觸發事件調用的方法}/// <summary>/// Rotates the matrix.Clockwise/// </summary>/// <returns>The matrix.</returns>/// <param name="matrix">Matrix.</param>/// <param name="n">N.</param>static Color32[] RotateMatrixByClockwise(Color32[] matrix, int n) {Color32[] ret = new Color32[n * n];for (int i = 0; i < n; ++i) {for (int j = 0; j < n; ++j) {ret[i*n + j] = matrix[(n - i - 1) * n + j];}}return ret;}/// <summary>/// anticlockwise/// </summary>/// <returns>The matrix.</returns>/// <param name="matrix">Matrix.</param>/// <param name="n">N.</param>static Color32[] RotateMatrixByAnticlockwise(Color32[] matrix, int n) {Color32[] ret = new Color32[n * n];for (int i = 0; i < n; ++i) {for (int j = 0; j < n; ++j) {ret[i*n + j] = matrix[(n - j - 1) * n + i];}}return ret;}}
如:
/// <summary>
/// write by 52cwalk,if you have some question ,please contract lycwalk@gmail.com
/// </summary>
///
/// using UnityEngine;
using System.Collections;
using UnityEngine.UI;public class QREncodeTest : MonoBehaviour {public QRCodeEncodeController e_qrController;public RawImage qrCodeImage;public InputField m_inputfield;// Use this for initializationvoid Start () {if (e_qrController != null) {e_qrController.e_QREncodeFinished += qrEncodeFinished;}}void qrEncodeFinished(Texture2D tex)     //觸發事件調用此方法{if (tex != null && tex != null) {qrCodeImage.texture = tex;} else {}}public void Encode()         {if (e_qrController != null) {string valueStr = m_inputfield.text;e_qrController.Encode(valueStr);        //傳入需要編譯成二維碼的string字段}}public void ClearCode(){qrCodeImage.texture = null;m_inputfield.text = "";}}

unity二維碼生成(新)相关推荐

  1. android 拍照无法生成图片,Android生成二維碼--拍照或從相冊選取圖片

    拍照或從相冊選擇圖片是我們日常開發中經常使用到的,可以說是必須掌握的東西.上一篇我介紹了如何生成自定義二維碼<Android生成自定義二維碼>,其中logo和代替黑色色塊的圖片都是寫死的, ...

  2. Android二維碼掃描

    总是站在牛人的肩膀上在~~ 直接上代码了 添加Gradle依赖:(其实都是人家的...) compile 'com.google.zxing:core:3.1.0' compile 'cn.bingo ...

  3. php 二维数组根据键值合并二维数组_php数组实现根据某个键值将相同键值合并生成新二维数组的方法详解...

    这篇文章主要介绍了php数组实现根据某个键值将相同键值合并生成新二维数组的方法,涉及php数组的遍历.赋值相关运算技巧,需要的朋友可以参考下 本文实例讲述了php数组实现根据某个键值将相同键值合并生成 ...

  4. Unity C# 网络学习(十二)——Protobuf生成协议

    Unity C# 网络学习(十二)--Protobuf生成协议 一.安装 去Protobuf官网下载对应操作系统的protoc,用于将.proto文件生成对应语言的协议语言文件 由于我使用的是C#所以 ...

  5. php 判断键值重复合并,php数组实现根据某个键值将相同键值合并生成新二维数组的方法...

    本文实例讲述了php数组实现根据某个键值将相同键值合并生成新二维数组的方法.分享给大家供大家参考,具体如下: 源数据: $infos = array( array( a => 36, b =&g ...

  6. matlab将三维模型渲染成二维视图,由三维图生成二维视图的新探讨

    由三维图生成二维视图的新探讨 2019-03-10 15:16:42次浏览 袁美荣 摘 要:该文将详细阐述利用AUTOCAD的模型空间和图纸空间实现三维实体到二维视图的自动转换的原理分析.关键命令SO ...

  7. 玩转Android之二维码生成与识别

    二维码,我们也称作QRCode,QR表示quick response即快速响应,在很多App中我们都能见到二维码的身影,最常见的莫过于微信了.那么今天我们就来看看怎么样在我们自己的App中集成二维码的 ...

  8. 支付宝支付 第五集:二维码生成工具

    支付宝支付 第五集:二维码生成工具 一.代码 目录结构 BufferedImageLuminanceSource.java package com.dzy.alipay.qrcode;import c ...

  9. Android之二维码生成与扫描

    转载请标明出处: http://blog.csdn.net/hai_qing_xu_kong/article/details/51260428 本文出自:[顾林海的博客] ##前言 月底离开公司,准备 ...

  10. 【Groovy】集合遍历 ( 使用集合的 collect 循环遍历集合并根据指定闭包规则生成新集合 | 代码示例 )

    文章目录 一.使用集合的 collect 循环遍历集合并根据指定闭包规则生成新集合 二.代码示例 一.使用集合的 collect 循环遍历集合并根据指定闭包规则生成新集合 调用集合的 collect ...

最新文章

  1. php+羊,PHP之羊生小羊的问题
  2. 感知和行动的贝叶斯模型
  3. 单击“登录”后,用户名和密码显示在地址栏中,不安全
  4. 计算机基本网络测试命令实验报告,实验三 基本网络测试工具的使用
  5. Debian11安装VLC Media Player视频播放器
  6. PE文件磁盘与内存映像结构图
  7. Spring Cloud 5分钟搭建教程
  8. 菜鸟教程Python教程100例(一)(持续更新)
  9. 第22课: JSP语句 switch判断语句 (JSP教程 JSP入门实战教程 黄菊华Java网站开发系列教程)
  10. 复杂的拉普拉斯逆变换
  11. SHELLEXECUTEINFO 和 ShellExecuteEx的使用
  12. 2021年南京市高考成绩查询,2021年南京各高中高考成绩排名及放榜最新消息
  13. 多进程中之文件描述符继承的消除
  14. 帆软 finereport FCRA 考试 题库+答案,共收录561题,大部分有答案
  15. 财经数据(5)-开盘啦股票标签数据爬虫
  16. File Struct 上传JPG格式图片变成tmp 服务器上传文件名字随机起
  17. 动态规划java实现数塔问题_动态规划入门_数塔问题
  18. Linux查看cc编译器版本,如何查看linux版本(转)
  19. 使用icacls命令设置目录及其子目录、文件的所有权限
  20. 四大天王 -- ContentProvider

热门文章

  1. 干货 | PCB多层板为什么都是偶数层?奇数层不行吗?
  2. 面试题:深拷贝和浅拷贝(超级详细,有内存图)
  3. 计算机自动开机什么愿意,电脑自动开关机是什么原因 怎么解决呢
  4. 实战:淘宝新品想抢占市场流量 分三步进行
  5. python输入个人所得税计算_python实例个税计算
  6. teamviewer Android 8,利用TeamViewer控制设备
  7. 使用Python3自带GUI tkinter 做的图形化操作SQLite3数据库的工具 v1.12 修修补补将就用
  8. Ubuntu18.04 使用gnome-tweak美化系统主题
  9. 计算机网络协议教案反思,《TCP/IP协议分析》教学实践与反思
  10. 判断分数是否为无限循环小数