Esempio n. 1
0
        public static byte[] GenerateQRCodeByte(string encode_data, QRCodeParams qRParams)
        {
            Image qrCodeImg = GenerateQRCodeImage(encode_data, qRParams);

            // Pasamos la imagen a bytes
            MemoryStream ms = new MemoryStream();

            qrCodeImg.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
            byte[] image = ms.ToArray();
            ms.Close();

            return(image);
        }
Esempio n. 2
0
        public static Image GenerateQRCodeImage(string encode_data, QRCodeParams qRParams)
        {
            Image image = null;

            try
            {
                QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();

                qrCodeEncoder.QRCodeEncodeMode   = qRParams.QRCodeEncodeMode;
                qrCodeEncoder.QRCodeScale        = qRParams.QRCodeScale;
                qrCodeEncoder.QRCodeVersion      = qRParams.QRCodeVersion;
                qrCodeEncoder.QRCodeErrorCorrect = qRParams.QRCodeErrorCorrect;

                if (encode_data.Length >= qRParams.QRCodeMaxLength)
                {
                    encode_data = encode_data.Substring(0, qRParams.QRCodeMaxLength);
                }

                image = qrCodeEncoder.Encode(encode_data);
            }
            catch { return(null); }

            return(image);
        }