• 二维码生成


    从vs Nugets搜索ThoughtWorks.QRCode下载ThoughtWorks.QRCode.dll

        private byte[] CreateQrcode(string code)
        {    
            string enCodeString = code;
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
            qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
            qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H;
            qrCodeEncoder.QRCodeScale = 3;
            qrCodeEncoder.QRCodeVersion = 8;
            Bitmap bitmap = qrCodeEncoder.Encode(enCodeString, Encoding.UTF8);
            //string filename = "QrCode.jpg";
            //bt.Save(filename);
    
            using (MemoryStream stream = new MemoryStream())
            {
                bitmap.Save(stream, ImageFormat.Jpeg);
                byte[] data = new byte[stream.Length];
                stream.Seek(0, SeekOrigin.Begin);
                stream.Read(data, 0, Convert.ToInt32(stream.Length));
                return data;
            }
        }

     上述二维码工具不适用与移动端,移动端可使用zxing插件

    代码如下

        public void ShowCode(string qrCode)
        {
            Texture2D qrCodeTex = new Texture2D(256, 256);
    
            if (qrCode != null)
            {
                //二维码写入图片
                var color32 = CreateQrcode(qrCode, qrCodeTex.width, qrCodeTex.height);
                qrCodeTex.SetPixels32(color32);
                qrCodeTex.Apply();
                qrCodeImage.texture = qrCodeTex;
                //重新赋值一张图,计算大小,避免白色边框过大
                //Texture2D modifiedQrcode = new Texture2D(190, 190);//创建目标图片大小
                //modifiedQrcode.SetPixels(qrCodeTex.GetPixels(32, 32, 190, 190));
                //modifiedQrcode.Apply();
                //qrCodeImage.texture = modifiedQrcode;
            }
        }
    
        //定义方法生成二维码
        private Color32[] CreateQrcode(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);
        }
  • 相关阅读:
    雪花算法 适用于ID 自增
    SB ,mybatis generator 插件 实现 更新操作
    spark优化
    Hive的导入导出方式汇总
    推荐系统架构图
    DBScan算法
    机器学习-逻辑回归算法
    机器学习-微博精准营销
    机器学习-TF-IDF算法
    机器学习-KNN识别手写数字
  • 原文地址:https://www.cnblogs.com/llstart-new0201/p/9723985.html
Copyright © 2020-2023  润新知