Example #1
0
        /// <summary>
        /// 生成二维码
        /// </summary>
        /// <param name="textForEncoding"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="logo"></param>
        /// <returns></returns>
        private Texture2D CreatQRcode(string textForEncoding, int width, int height, Texture2D logo = null)
        {
            if (string.IsNullOrEmpty(textForEncoding))
            {
                return(null);
            }
            encode = new Texture2D(width, height, TextureFormat.RGBA32, false);
            var colors = MsgTool.Encode(textForEncoding, encode.width, encode.height);

            encode.SetPixels32(colors);
            if (logo != null)
            {
                int       x         = (encode.width - logo.width) / 2;
                int       y         = (encode.height - logo.height) / 2;
                Color32[] colorlogo = logo.GetPixels32();
                encode.SetPixels32(x, y, logo.width, logo.height, colorlogo);
            }
            encode.Apply();
            return(encode);
        }
Example #2
0
        private Texture2D CreatQRcode(string textForEncoding, Texture2D logo = null)
        {
            if (string.IsNullOrEmpty(textForEncoding))
            {
                return(null);
            }
            int num = Random.Range(1, 3);

            switch (num)
            {
            case 1:
                _post1Image.gameObject.SetActive(true);
                break;

            case 2:
                _post2Image.gameObject.SetActive(true);
                break;

            case 3:
                _post3Image.gameObject.SetActive(true);
                break;
            }

            //TODO之后可以去除
            Texture2D encode = new Texture2D(100, 100, TextureFormat.RGBA32, false);
            var       colors = MsgTool.Encode(textForEncoding, encode.width, encode.height);

            encode.SetPixels32(colors);
            //if (logo != null)
            //{
            //    int x = (encode.width-logo.width) / 2;
            //    int y = (encode.height-logo.height) / 2;
            //    Color32[] colorlogo = logo.GetPixels32();
            //    encode.SetPixels32(x,y,logo.width,logo.height,colorlogo);
            //}
            encode.Apply();
            return(encode);
        }