当前位置:   article > 正文

Unity生成二维码功能_unity 上传图片oss 生成二维码

unity 上传图片oss 生成二维码

当时在做的时候,找了好多dll,最好找到这个dll,  什么都不说啦!

   public Texture2D encoded;//生成的二维码为Texture2D类型  

    public string Lastresult;//二维码中所包含的内容信息,我是使用了GUID进行代替  
    public int count = 1;//生成几个二维码  
    void Start ()
    {
        encoded = new Texture2D(256, 256);
        for (int i = 0; i < count; i++)
        {
            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/" + textForEncoding + ".png";
                System.IO.File.WriteAllBytes(fileName, bytes);
            }
        }
    }
    private static Color32[] Encode(string textForEncoding, int width, int height)
    {
        Dictionary<EncodeHintType, object> hints = new Dictionary<EncodeHintType, object>();
        hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8");                                                  //默认的编码不支持中文,将输入内容的编码格式
        var encoder = new QRCodeWriter
        {


        };
        var writer = new BarcodeWriter
        {
            //Format = BarcodeFormat.QR_CODE,
            //Options = new QrCodeEncodingOptions
            //{
            //    Height = height,
            //    Width = width,
            //},
            Encoder = encoder
        };
        var bitMatrix = writer.Encoder.encode(textForEncoding, BarcodeFormat.QR_CODE, width, height, hints);
        return writer.Write(bitMatrix);

    }


dll的百度云盘地址:链接: http://pan.baidu.com/s/1pLavJmz 密码: wqyb

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/715880
推荐阅读
相关标签
  

闽ICP备14008679号