zoukankan      html  css  js  c++  java
  • Unity3d生成二维码

    首先下载ZXing.Net.0.12.0.0.zip,下载地址为http://zxingnet.codeplex.com/

    然后找到其中的unity文件夹,将文件夹放到Unity的工程内。

    脚本:

    using UnityEngine;
    using System.Collections;
    using ZXing;
    using ZXing.QrCode;
    public class BarcodeCam: MonoBehaviour 
    {

        public Texture2D encoded;

        public string Lastresult;

        void Start () 
        {
            encoded = new Texture2D(256, 256);
            Lastresult = "http://www.google.com";
        }

        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 Update () 
        {
            var textForEncoding = Lastresult;
            if (textForEncoding != null)
            {
                var color32 = Encode(textForEncoding, encoded.width, encoded.height);
                encoded.SetPixels32(color32);
                encoded.Apply();
            }
        }


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

    将脚本挂在一个空物体上、运行、即可生成二维码

    转自:http://blog.csdn.net/liulala16/article/details/14521979

  • 相关阅读:
    qt的.pro配置总结
    【GOJ 1489】Monster Hunter
    CPU 杂谈
    【CF 1061C|GOJ 3505】Multiplicity
    【CF 1039D|GOJ 3502】You Are Given a Tree
    我跳过的坑
    【CF 1101D|GOJ 3501】GCD Counting
    【HDU 5269|GOJ 739】xor的最低位
    beta阶段组间的140字互评
    【第七周】【新蜂站会】3
  • 原文地址:https://www.cnblogs.com/Yellow0-0River/p/4239297.html
Copyright © 2011-2022 走看看