Esempio n. 1
0
 public void SaveQrCode(string data, string filename, QRCoder.QRCodeGenerator.ECCLevel err_cor)
 {
     QRCoder.QRCodeData qr_data = qgen.CreateQrCode(data, err_cor);
     qrCode = new QRCoder.QRCode(qr_data);
     bitmap = qrCode.GetGraphic(100, Color.Black, Color.White, false);
     bitmap.Save(filename);
 }
Esempio n. 2
0
        /// <summary>
        /// Рисует QR код
        /// </summary>
        /// <param name="data">данный</param>
        /// <param name="g">объект графики</param>
        /// <param name="z">размер квадрата</param>
        /// <param name="p">координаты левого верхнего угла</param>
        ///  <param name="err_cor">уровень коррекции ошибок</param>
        public void DrawQrCode(string data, Graphics g, int z, PointF p, QRCoder.QRCodeGenerator.ECCLevel err_cor)
        {
            QRCoder.QRCodeData qr_data = qgen.CreateQrCode(data, err_cor);
            qrCode = new QRCoder.QRCode(qr_data);
            bitmap = qrCode.GetGraphic(10, Color.Black, Color.White, false);
            float h = z * (float)3.779527559055;

            g.DrawImage(bitmap, p.X, p.Y, h, h);
        }
Esempio n. 3
0
        public static string GetQRCodeEmbeddedImg(string identity, byte[] secret, QRCoder.QRCodeGenerator.ECCLevel size)
        {
            string base32Secret = GetSecretCode(secret);
            string keyUri       = string.Format("otpauth://totp/{0}?secret={1}", System.Web.HttpUtility.UrlEncode(identity), base32Secret);

            QRCoder.QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator();
            QRCoder.QRCodeData      qrCodeData  = qrGenerator.CreateQrCode(keyUri, size);
            QRCoder.QRCode          qrCode      = new QRCoder.QRCode(qrCodeData);
            Bitmap qrCodeImage = qrCode.GetGraphic(size == QRCoder.QRCodeGenerator.ECCLevel.L ? 5 : (size == QRCoder.QRCodeGenerator.ECCLevel.M || size == QRCoder.QRCodeGenerator.ECCLevel.H ? 10 : 20));

            using (MemoryStream ms = new MemoryStream())
            {
                qrCodeImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                byte[] png      = ms.GetBuffer();
                string imageUrl = "data:image/png;base64," + Convert.ToBase64String(png);
                return(imageUrl);
            }
        }
Esempio n. 4
0
        private void SetQrCoder()
        {
            string context  = textBoxContext.Text.Trim();
            string strLevel = CEELevel.SelectedItem.ToString();

            QRCoder.QRCodeGenerator.ECCLevel level = default(QRCoder.QRCodeGenerator.ECCLevel);
            if (!Enum.TryParse(strLevel, out level))
            {
                MessageBox.Show("未知纠错码等级!");
            }
            using (QRCoder.QRCodeGenerator cenerator = new QRCoder.QRCodeGenerator())
            {
                var qrCodeData = cenerator.CreateQrCode(context, level, true);
                using (QRCoder.QRCode rCode = new QRCoder.QRCode(qrCodeData))
                {
                    this.pictureBox1.Image    = rCode.GetGraphic(10, Color.Black, Color.White, icon: GetIconBitmap(), iconSizePercent: (int)textBoxImageSize.Value);
                    pictureBox1.Size          = new Size(pictureBox1.Width, pictureBox1.Height);
                    this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                }
            }
        }