zoukankan      html  css  js  c++  java
  • 通过Unity3d创建二维码(利用zxing2.2)

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

    首先 下载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 
    {
    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);
        }


        public Texture2D encoded;
        public string Lastresult;
    }

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

  • 相关阅读:
    java中清空session
    freemarker中修改和添加功能中包含checkbox复选框默认选中需求的解决方式
    Highcharts动态赋值学习
    CSDN Luncher
    JS导入导出Excel表格的方法
    js 下载文件的操作方法
    模板标签的作用
    css3的calc()
    JS滚轮mousewheel事件和DOMMouseScroll事件
    css BFC(格式化上下文)的理解
  • 原文地址:https://www.cnblogs.com/123ing/p/4126822.html
Copyright © 2011-2022 走看看