Esempio n. 1
0
 /// <summary>
 /// 生成二维码
 /// </summary>
 /// <param name="value">需要生成的值</param>
 /// <param name="pixelsPerModule">像素</param>
 /// <param name="level">级别</param>
 /// <param name="drawQuietZones">是否生成白色边框</param>
 /// <param name="ico">ico logo</param>
 /// <param name="iconSizePercent">log大小比例</param>
 /// <param name="iconBorderWidth">log的边框</param>
 /// <returns></returns>
 public Bitmap GetQRCode(string value, int pixelsPerModule = 8, QRCodeLevel level = QRCodeLevel.M, bool drawQuietZones = true, Bitmap ico = null, int iconSizePercent = 15, int iconBorderWidth = 6)
 {
     QRCoder.QRCodeGenerator Tool   = new QRCoder.QRCodeGenerator();
     QRCoder.QRCodeData      data   = Tool.CreateQrCode(value, (QRCoder.QRCodeGenerator.ECCLevel)((int)level), true);
     QRCoder.QRCode          qrcode = new QRCoder.QRCode(data);
     return(qrcode.GetGraphic(pixelsPerModule, Color.Black, Color.White, ico, iconSizePercent, iconBorderWidth, drawQuietZones));
 }
Esempio n. 2
0
        public byte[] Create(string data, QRCodeLevel level, int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex)
        {
            QRCodeGenerator.ECCLevel lv = (QRCodeGenerator.ECCLevel)((int)level);
            var qrcodeData        = CreateQrCode(data, lv);
            BitmapByteQRCode code = new BitmapByteQRCode(qrcodeData);

            return(code.GetGraphic(pixelsPerModule, darkColorHtmlHex: darkColorHtmlHex, lightColorHtmlHex: lightColorHtmlHex));
        }
Esempio n. 3
0
        public byte[] Create(string data, QRCodeLevel level = QRCodeLevel.Q, int pixelsPerModule = 20)
        {
            QRCodeGenerator.ECCLevel lv = (QRCodeGenerator.ECCLevel)((int)level);
            var qrcodeData        = CreateQrCode(data, lv);
            BitmapByteQRCode code = new BitmapByteQRCode(qrcodeData);

            return(code.GetGraphic(pixelsPerModule));
        }
Esempio n. 4
0
        /// <summary>
        /// 创建二维码
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public static string Create(string str, int _size, string destImg = "", bool _combin = false, QRCodeLevel _levet = QRCodeLevel.M, QRCodeVersion _ver = QRCodeVersion.A, QRCodeType _type = QRCodeType.Byte)
        {
            var _result = string.Empty;
            var fullpath = string.Empty;
            var filepath = System.Web.HttpContext.Current.Server.MapPath(@"~\QRCode\upload") + "\\";
            if (string.IsNullOrEmpty(destImg))
            {
                destImg = filepath + "favicon.png";
            }
            if (string.IsNullOrEmpty(str))
            {
                _result = "[{\"status\":0,\"count\":1,\"content\":\"" + "亲内容去哪里了".ChinessConvertToUnicodeString() + "\"}]";
                return _result;
            }

            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
            String encoding = _type.ToString();
            if (encoding == "Byte")
            {
                qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
            }
            else if (encoding == "AlphaNumeric")
            {
                qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC;
            }
            else if (encoding == "Numeric")
            {
                qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.NUMERIC;
            }

            try
            {
                int scale = _size;
                qrCodeEncoder.QRCodeScale = scale;
            }
            catch (Exception ex)
            {
                //throw new Exception(ex.ToString());
                _result = "[{\"status\":0,\"count\":1,\"content\":\"" + "大小设置出错".ChinessConvertToUnicodeString() + "\"}]";
                return _result;
            }
            try
            {
                int version = Convert.ToInt16(_ver);
                qrCodeEncoder.QRCodeVersion = version + 1;
            }
            catch (Exception ex)
            {
                //throw new Exception(ex.ToString());
                _result = "[{\"status\":0,\"count\":1,\"content\":\"" + "版本设置出错".ChinessConvertToUnicodeString() + "\"}]";
                return _result;
            }
            string errorCorrect = _levet.ToString();
            if (errorCorrect == "L")
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.L;
            else if (errorCorrect == "M")
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
            else if (errorCorrect == "Q")
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.Q;
            else if (errorCorrect == "H")
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H;

            Image image;

            image = qrCodeEncoder.Encode(ConverToGB(str, 16));

            var filename = Guid.NewGuid().ToString() + ".png";

            fullpath = filepath + filename;

            if (!Directory.Exists(filepath))
            {
                Directory.CreateDirectory(filepath);
            }
            fullpath = filepath + filename;
            if (_combin)
            {
                CombinImage(image, destImg, true);
            }
            image.Dispose();
            _result = "[{\"status\":1,\"count\":1,\"content\":\"" + str + "\",\"list\":[{\"imgurl\":\"" + fullpath + "\"}]}]";

            return _result;
        }
 public static bool ToPrinterQRCodeLevel(string value, out QRCodeLevel output)
 {
     return(PrinterQRCodeLevelDictionary.TryGetKey(value, out output));
 }