zoukankan      html  css  js  c++  java
  • 简易版生成二维码

    先在Assets工程 里Plugins配置文件夹 放一个zxing.unity.dll动态链接库

    /*              #########                       
                  ############                     
                  #############                    
                 ##  ###########                   
                ###  ###### #####                  
                ### #######   ####                 
               ###  ########## ####                
              ####  ########### ####               
             ####   ###########  #####             
            #####   ### ########   #####           
           #####   ###   ########   ######         
          ######   ###  ###########   ######       
         ######   #### ##############  ######      
        #######  #####################  ######     
        #######  ######################  ######    
       #######  ###### #################  ######   
       #######  ###### ###### #########   ######   
       #######    ##  ######   ######     ######   
       #######        ######    #####     #####    
        ######        #####     #####     ####     
         #####        ####      #####     ###      
          #####       ###        ###      #        
            ###       ###        ###              
             ##       ###        ###               
    __________#_______####_______####______________
        身是菩提树,心如明镜台,时时勤拂拭,勿使惹尘埃。
                    我们的未来没有BUG              
    * ==============================================================================
    * Filename: Instering
    * Created:  2017/8/1
    * Author:   WYC
    * Purpose:  生成的二维码为Texture2D类型
    * ==============================================================================
    */
    using System.IO;
    using UnityEngine;
    using ZXing;
    using ZXing.QrCode;
    
    public class BarcodeCamme : MonoBehaviour {
    
        public Texture2D encoded;//生成的二维码为Texture2D类型  
        public string Lastresult;//二维码中所包含的内容信息,我是使用了GUID进行代替  
    
        void Start()
        {
    
            encoded = new Texture2D(256, 256);
            Lastresult = "http://www.vrts.co/1.jpg";//根据这个网址生成二维码
    
            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/二维码.png";
                File.WriteAllBytes(fileName, bytes);
            }
            
        }
    
    
        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);
        }
    
      
    
    }
  • 相关阅读:
    001-Java®语言规范、Java平台标准版文档、JVM概述
    004-RIP、OSPF【路由选择协议】
    003-ARP地址解析协议
    0405-服务注册与发现-客户端负载均衡-Ribbon 同Eureka使用,Ribbon脱离Eureka使用
    0404-服务注册与发现-客户端负载均衡-两种自定义方式-Ribbon通过代码自定义配置、使用配置文件自定义Ribbon Client
    网页嵌入swf代码
    解决html5 video不能播放 能播放声音不能播放视频
    代码高亮插件SyntaxHighlighter
    透明度
    web图片轮播实现
  • 原文地址:https://www.cnblogs.com/mclll520/p/7814467.html
Copyright © 2011-2022 走看看