Exemplo n.º 1
0
        /// <summary>
        /// 生成二维码
        /// </summary>
        /// <param name="msg">信息</param>
        /// <param name="version">版本 1 ~ 40</param>
        /// <param name="pixel">像素点大小</param>
        /// <param name="icon_path">图标路径</param>
        /// <param name="icon_size">图标尺寸</param>
        /// <param name="icon_border">图标边框厚度</param>
        /// <param name="white_edge">二维码白边</param>
        /// <returns>位图</returns>
        public static Bitmap QRCode(string msg, int version, int pixel, string icon_path, int icon_size, int icon_border, bool white_edge)
        {
            QRCoder.QRCodeGenerator code_generator = new QRCoder.QRCodeGenerator();

            QRCoder.QRCodeData code_data = code_generator.CreateQrCode(msg, QRCoder.QRCodeGenerator.ECCLevel.M /* 这里设置容错率的一个级别 */, true, true, QRCoder.QRCodeGenerator.EciMode.Utf8, version);

            QRCoder.QRCode code = new QRCoder.QRCode(code_data);

            Bitmap icon = new Bitmap(icon_path);

            Bitmap bmp = code.GetGraphic(pixel, Color.Black, Color.White, icon, icon_size, icon_border, white_edge);

            return(bmp);
        }
        public byte[] cargarDatos(string dato)
        {
            var crypt          = new SimpleInteroperableEncryption(ConfigurationManager.AppSettings["MetodoEncriptacion"].ToString());
            var datoEncriptado = crypt.Encrypt(dato);

            QRCoder.QRCodeGenerator qRCodeGenerator = new QRCoder.QRCodeGenerator();
            QRCoder.QRCodeData      qRCodeData      = qRCodeGenerator.CreateQrCode(datoEncriptado, QRCoder.QRCodeGenerator.ECCLevel.Q);
            QRCoder.QRCode          qRCode          = new QRCoder.QRCode(qRCodeData);
            //transformamos en bits
            Bitmap bmp = qRCode.GetGraphic(7);

            using (MemoryStream ms = new MemoryStream())
            {
                //importante para generar el qr
                bmp.Save(ms, ImageFormat.Bmp);
                //row.CodigoQR = ms.ToArray();

                return(ms.ToArray());
            }
        }
Exemplo n.º 3
0
 protected AbstractQRCode(QRCodeData data)
 {
     this.QrCodeData = data;
 }
Exemplo n.º 4
0
 public static void PlaceDataWords(ref QRCodeData qrCode, string data, ref List<Rectangle> blockedModules)
 {
     var size = qrCode.ModuleMatrix.Count;
     var up = true;
     var datawords = new Queue<bool>();
     data.ToList().ForEach(x => datawords.Enqueue(x != '0'));
     for (var x = size - 1; x >= 0; x = x - 2)
     {
         if (x == 6)
             x = 5;
         for (var yMod = 1; yMod <= size; yMod++)
         {
             int y;
             if (up)
             {
                 y = size - yMod;
                 if (datawords.Count > 0 && !IsBlocked(new Rectangle(x, y, 1, 1), blockedModules))
                     qrCode.ModuleMatrix[y][x] = datawords.Dequeue();
                 if (datawords.Count > 0 && x > 0 && !IsBlocked(new Rectangle(x - 1, y, 1, 1), blockedModules))
                     qrCode.ModuleMatrix[y][x - 1] = datawords.Dequeue();
             }
             else
             {
                 y = yMod - 1;
                 if (datawords.Count > 0 && !IsBlocked(new Rectangle(x, y, 1, 1), blockedModules))
                     qrCode.ModuleMatrix[y][x] = datawords.Dequeue();
                 if (datawords.Count > 0 && x > 0 && !IsBlocked(new Rectangle(x - 1, y, 1, 1), blockedModules))
                     qrCode.ModuleMatrix[y][x - 1] = datawords.Dequeue();
             }
         }
         up = !up;
     }
 }
Exemplo n.º 5
0
 public XamlQRCode(QRCodeData data) : base(data)
 {
 }
Exemplo n.º 6
0
 public Base64QRCode(QRCodeData data) : base(data)
 {
     qr = new QRCode(data);
 }
Exemplo n.º 7
0
 public void Dispose()
 {
     this.QrCodeData = null;
 }
Exemplo n.º 8
0
 public SvgQRCode(QRCodeData data) : base(data)
 {
 }
Exemplo n.º 9
0
 public UnityQRCode(QRCodeData data) : base(data)
 {
 }
Exemplo n.º 10
0
 public static void PlaceTimingPatterns(ref QRCodeData qrCode, ref List<Rectangle> blockedModules)
 {
     var size = qrCode.ModuleMatrix.Count;
     for (var i = 8; i < size - 8; i++)
     {
         if (i % 2 == 0)
         {
             qrCode.ModuleMatrix[6][i] = true;
             qrCode.ModuleMatrix[i][6] = true;
         }
     }
     blockedModules.AddRange(new[]{
         new Rectangle(6, 8, 1, size-16),
         new Rectangle(8, 6, size-16, 1)
     });
 }
Exemplo n.º 11
0
 public static void AddQuietZone(ref QRCodeData qrCode)
 {
     bool[] quietLine = new bool[qrCode.ModuleMatrix.Count + 8];
     for (int i = 0; i < quietLine.Length; i++)
         quietLine[i] = false;
     for (int i = 0; i < 4; i++)
         qrCode.ModuleMatrix.Insert(0, new BitArray(quietLine));
     for (int i = 0; i < 4; i++)
         qrCode.ModuleMatrix.Add(new BitArray(quietLine));
     for (int i = 4; i < qrCode.ModuleMatrix.Count - 4; i++)
     {
         bool[] quietPart = new bool[4] { false, false, false, false };
         List<bool> tmpLine = new List<bool>(quietPart);
         foreach (bool module in qrCode.ModuleMatrix[i])
             tmpLine.Add(module);
         tmpLine.AddRange(quietPart);
         qrCode.ModuleMatrix[i] = new BitArray(tmpLine.ToArray());
     }
 }
Exemplo n.º 12
0
                public static int Score(ref QRCodeData qrCode)
                {
                    var score = 0;
                    var size = qrCode.ModuleMatrix.Count;

                    //Penalty 1                   
                    for (int y = 0; y < size; y++)
                    {
                        var modInRow = 0;
                        var modInColumn = 0;
                        var lastValRow = qrCode.ModuleMatrix[y][0];
                        var lastValColumn = qrCode.ModuleMatrix[0][y];
                        for (int x = 0; x < size; x++)
                        {
                            if (qrCode.ModuleMatrix[y][x] == lastValRow)
                                modInRow++;
                            else
                                modInRow = 1;
                            if (modInRow == 5)
                                score += 3;
                            else if (modInRow > 5)
                                score++;
                            lastValRow = qrCode.ModuleMatrix[y][x];


                            if (qrCode.ModuleMatrix[x][y] == lastValColumn)
                                modInColumn++;
                            else
                                modInColumn = 1;
                            if (modInColumn == 5)
                                score += 3;
                            else if (modInColumn > 5)
                                score++;
                            lastValColumn = qrCode.ModuleMatrix[x][y];
                        }
                    }


                    //Penalty 2
                    for (int y = 0; y < size - 1; y++)
                    {
                        for (int x = 0; x < size - 1; x++)
                        {
                            if (qrCode.ModuleMatrix[y][x] == qrCode.ModuleMatrix[y][x + 1] &&
                                qrCode.ModuleMatrix[y][x] == qrCode.ModuleMatrix[y + 1][x] &&
                                qrCode.ModuleMatrix[y][x] == qrCode.ModuleMatrix[y + 1][x + 1])
                                score += 3;
                        }
                    }

                    //Penalty 3
                    for (int y = 0; y < size; y++)
                    {
                        for (int x = 0; x < size - 10; x++)
                        {
                            if ((qrCode.ModuleMatrix[y][x] &&
                                !qrCode.ModuleMatrix[y][x + 1] &&
                                qrCode.ModuleMatrix[y][x + 2] &&
                                qrCode.ModuleMatrix[y][x + 3] &&
                                qrCode.ModuleMatrix[y][x + 4] &&
                                !qrCode.ModuleMatrix[y][x + 5] &&
                                qrCode.ModuleMatrix[y][x + 6] &&
                                !qrCode.ModuleMatrix[y][x + 7] &&
                                !qrCode.ModuleMatrix[y][x + 8] &&
                                !qrCode.ModuleMatrix[y][x + 9] &&
                                !qrCode.ModuleMatrix[y][x + 10]) ||
                                (!qrCode.ModuleMatrix[y][x] &&
                                !qrCode.ModuleMatrix[y][x + 1] &&
                                !qrCode.ModuleMatrix[y][x + 2] &&
                                !qrCode.ModuleMatrix[y][x + 3] &&
                                qrCode.ModuleMatrix[y][x + 4] &&
                                !qrCode.ModuleMatrix[y][x + 5] &&
                                qrCode.ModuleMatrix[y][x + 6] &&
                                qrCode.ModuleMatrix[y][x + 7] &&
                                qrCode.ModuleMatrix[y][x + 8] &&
                                !qrCode.ModuleMatrix[y][x + 9] &&
                                qrCode.ModuleMatrix[y][x + 10]))
                            {
                                score += 40;
                            }

                            if ((qrCode.ModuleMatrix[x][y] &&
                                !qrCode.ModuleMatrix[x + 1][y] &&
                                qrCode.ModuleMatrix[x + 2][y] &&
                                qrCode.ModuleMatrix[x + 3][y] &&
                                qrCode.ModuleMatrix[x + 4][y] &&
                                !qrCode.ModuleMatrix[x + 5][y] &&
                                qrCode.ModuleMatrix[x + 6][y] &&
                                !qrCode.ModuleMatrix[x + 7][y] &&
                                !qrCode.ModuleMatrix[x + 8][y] &&
                                !qrCode.ModuleMatrix[x + 9][y] &&
                                !qrCode.ModuleMatrix[x + 10][y]) ||
                                (!qrCode.ModuleMatrix[x][y] &&
                                !qrCode.ModuleMatrix[x + 1][y] &&
                                !qrCode.ModuleMatrix[x + 2][y] &&
                                !qrCode.ModuleMatrix[x + 3][y] &&
                                qrCode.ModuleMatrix[x + 4][y] &&
                                !qrCode.ModuleMatrix[x + 5][y] &&
                                qrCode.ModuleMatrix[x + 6][y] &&
                                qrCode.ModuleMatrix[x + 7][y] &&
                                qrCode.ModuleMatrix[x + 8][y] &&
                                !qrCode.ModuleMatrix[x + 9][y] &&
                                qrCode.ModuleMatrix[x + 10][y]))
                            {
                                score += 40;
                            }
                        }
                    }

                    //Penalty 4
                    var blackModules = 0;
                    foreach (var row in qrCode.ModuleMatrix)
                        foreach (bool bit in row)
                            if (bit)
                                blackModules++;

                    var percent = (blackModules / (qrCode.ModuleMatrix.Count * qrCode.ModuleMatrix.Count)) * 100;
                    if (percent % 5 == 0)
                        score += Math.Min((Math.Abs(percent - 55) / 5), (Math.Abs(percent - 45) / 5)) * 10;
                    else
                        score += Math.Min((Math.Abs((int)Math.Floor((decimal)percent / 5) - 50) / 5), (Math.Abs(((int)Math.Floor((decimal)percent / 5) + 5) - 50) / 5)) * 10;

                    return score;
                }
Exemplo n.º 13
0
            public static int MaskCode(ref QRCodeData qrCode, int version, ref List<Rectangle> blockedModules)
            {
                var patternName = string.Empty;
                var patternScore = 0;

                var size = qrCode.ModuleMatrix.Count;

                foreach (var pattern in typeof(MaskPattern).GetMethods())
                {
                    if (pattern.Name.Length == 8 && pattern.Name.Substring(0, 7) == "Pattern")
                    {
                        QRCodeData qrTemp = new QRCodeData(version);
                        for (int y = 0; y < size; y++)
                        {
                            for (int x = 0; x < size; x++)
                            {
                                qrTemp.ModuleMatrix[y][x] = qrCode.ModuleMatrix[y][x];
                            }

                        }

                        for (int x = 0; x < size; x++)
                        {
                            for (int y = 0; y < size; y++)
                            {
                                if (!IsBlocked(new Rectangle(x, y, 1, 1), blockedModules))
                                {
                                    qrTemp.ModuleMatrix[y][x] ^= (bool)pattern.Invoke(null, new object[] { x, y });
                                }
                            }
                        }

                        var score = MaskPattern.Score(ref qrTemp);
                        if (string.IsNullOrEmpty(patternName) || patternScore > score)
                        {
                            patternName = pattern.Name;
                            patternScore = score;
                        }

                    }
                }
                var patterMethod = typeof(MaskPattern).GetMethods().Where(x => x.Name == patternName).First();
                for (int x = 0; x < size; x++)
                {
                    for (int y = 0; y < size; y++)
                    {
                        if (!IsBlocked(new Rectangle(x, y, 1, 1), blockedModules))
                        {
                            qrCode.ModuleMatrix[y][x] ^= (bool)patterMethod.Invoke(null, new object[] { x, y });
                        }
                    }
                }
                return Convert.ToInt32(patterMethod.Name.Substring(patterMethod.Name.Length - 1, 1)) - 1;
            }
Exemplo n.º 14
0
 public SvgQRCode(QRCodeData data, bool qrpath = false) : base(data, qrpath)
 {
 }
Exemplo n.º 15
0
 public QRCode(QRCodeData data)
 {
     this.QrCodeData = data;
 }
Exemplo n.º 16
0
            public static void PlaceFinderPatterns(ref QRCodeData qrCode, ref List<Rectangle> blockedModules)
            {
                var size = qrCode.ModuleMatrix.Count;
                int[] locations = { 0, 0, size - 7, 0, 0, size - 7 };

                for (var i = 0; i < 6; i = i + 2)
                {
                    for (var x = 0; x < 7; x++)
                    {
                        for (var y = 0; y < 7; y++)
                        {
                            if (!(((x == 1 || x == 5) && y > 0 && y < 6) || (x > 0 && x < 6 && (y == 1 || y == 5))))
                            {
                                qrCode.ModuleMatrix[y + locations[i + 1]][x + locations[i]] = true;
                            }
                        }
                    }
                    blockedModules.Add(new Rectangle(locations[i], locations[i + 1], 7, 7));
                }
            }
Exemplo n.º 17
0
                public static int Score(ref QRCodeData qrCode)
                {
                    int score1 = 0,
                        score2 = 0,
                        score3 = 0,
                        score4 = 0;
                    var size = qrCode.ModuleMatrix.Count;

                    //Penalty 1
                    for (var y = 0; y < size; y++)
                    {
                        var modInRow = 0;
                        var modInColumn = 0;
                        var lastValRow = qrCode.ModuleMatrix[y][0];
                        var lastValColumn = qrCode.ModuleMatrix[0][y];
                        for (var x = 0; x < size; x++)
                        {
                            if (qrCode.ModuleMatrix[y][x] == lastValRow)
                                modInRow++;
                            else
                                modInRow = 1;
                            if (modInRow == 5)
                                score1 += 3;
                            else if (modInRow > 5)
                                score1++;
                            lastValRow = qrCode.ModuleMatrix[y][x];

                            if (qrCode.ModuleMatrix[x][y] == lastValColumn)
                                modInColumn++;
                            else
                                modInColumn = 1;
                            if (modInColumn == 5)
                                score1 += 3;
                            else if (modInColumn > 5)
                                score1++;
                            lastValColumn = qrCode.ModuleMatrix[x][y];
                        }
                    }

                    //Penalty 2
                    for (var y = 0; y < size - 1; y++)
                    {
                        for (var x = 0; x < size - 1; x++)
                        {
                            if (qrCode.ModuleMatrix[y][x] == qrCode.ModuleMatrix[y][x + 1] &&
                                qrCode.ModuleMatrix[y][x] == qrCode.ModuleMatrix[y + 1][x] &&
                                qrCode.ModuleMatrix[y][x] == qrCode.ModuleMatrix[y + 1][x + 1])
                                score2 += 3;
                        }
                    }

                    //Penalty 3
                    for (var y = 0; y < size; y++)
                    {
                        for (var x = 0; x < size - 10; x++)
                        {
                            if ((qrCode.ModuleMatrix[y][x] &&
                                !qrCode.ModuleMatrix[y][x + 1] &&
                                qrCode.ModuleMatrix[y][x + 2] &&
                                qrCode.ModuleMatrix[y][x + 3] &&
                                qrCode.ModuleMatrix[y][x + 4] &&
                                !qrCode.ModuleMatrix[y][x + 5] &&
                                qrCode.ModuleMatrix[y][x + 6] &&
                                !qrCode.ModuleMatrix[y][x + 7] &&
                                !qrCode.ModuleMatrix[y][x + 8] &&
                                !qrCode.ModuleMatrix[y][x + 9] &&
                                !qrCode.ModuleMatrix[y][x + 10]) ||
                                (!qrCode.ModuleMatrix[y][x] &&
                                !qrCode.ModuleMatrix[y][x + 1] &&
                                !qrCode.ModuleMatrix[y][x + 2] &&
                                !qrCode.ModuleMatrix[y][x + 3] &&
                                qrCode.ModuleMatrix[y][x + 4] &&
                                !qrCode.ModuleMatrix[y][x + 5] &&
                                qrCode.ModuleMatrix[y][x + 6] &&
                                qrCode.ModuleMatrix[y][x + 7] &&
                                qrCode.ModuleMatrix[y][x + 8] &&
                                !qrCode.ModuleMatrix[y][x + 9] &&
                                qrCode.ModuleMatrix[y][x + 10]))
                            {
                                score3 += 40;
                            }

                            if ((qrCode.ModuleMatrix[x][y] &&
                                !qrCode.ModuleMatrix[x + 1][y] &&
                                qrCode.ModuleMatrix[x + 2][y] &&
                                qrCode.ModuleMatrix[x + 3][y] &&
                                qrCode.ModuleMatrix[x + 4][y] &&
                                !qrCode.ModuleMatrix[x + 5][y] &&
                                qrCode.ModuleMatrix[x + 6][y] &&
                                !qrCode.ModuleMatrix[x + 7][y] &&
                                !qrCode.ModuleMatrix[x + 8][y] &&
                                !qrCode.ModuleMatrix[x + 9][y] &&
                                !qrCode.ModuleMatrix[x + 10][y]) ||
                                (!qrCode.ModuleMatrix[x][y] &&
                                !qrCode.ModuleMatrix[x + 1][y] &&
                                !qrCode.ModuleMatrix[x + 2][y] &&
                                !qrCode.ModuleMatrix[x + 3][y] &&
                                qrCode.ModuleMatrix[x + 4][y] &&
                                !qrCode.ModuleMatrix[x + 5][y] &&
                                qrCode.ModuleMatrix[x + 6][y] &&
                                qrCode.ModuleMatrix[x + 7][y] &&
                                qrCode.ModuleMatrix[x + 8][y] &&
                                !qrCode.ModuleMatrix[x + 9][y] &&
                                qrCode.ModuleMatrix[x + 10][y]))
                            {
                                score3 += 40;
                            }
                        }
                    }

                    //Penalty 4
                    double blackModules = 0;
                    foreach (var row in qrCode.ModuleMatrix)
                        foreach (bool bit in row)
                            if (bit)
                                blackModules++;

                    var percent = (blackModules / (qrCode.ModuleMatrix.Count * qrCode.ModuleMatrix.Count)) * 100;
                    var prevMultipleOf5 = Math.Abs((int) Math.Floor(percent/5)*5 - 50)/5;
                    var nextMultipleOf5 = Math.Abs((int)Math.Floor(percent / 5) * 5 -45)/5;
                    score4 = Math.Min(prevMultipleOf5, nextMultipleOf5)*10;

                    return score1 + score2 + score3 + score4;
                }
Exemplo n.º 18
0
 public static void PlaceFormat(ref QRCodeData qrCode, string formatStr)
 {
     var size = qrCode.ModuleMatrix.Count;
     var fStr = new string(formatStr.Reverse().ToArray());
     var modules = new[,] { { 8, 0, size - 1, 8 }, { 8, 1, size - 2, 8 }, { 8, 2, size - 3, 8 }, { 8, 3, size - 4, 8 }, { 8, 4, size - 5, 8 }, { 8, 5, size - 6, 8 }, { 8, 7, size - 7, 8 }, { 8, 8, size - 8, 8 }, { 7, 8, 8, size - 7 }, { 5, 8, 8, size - 6 }, { 4, 8, 8, size - 5 }, { 3, 8, 8, size - 4 }, { 2, 8, 8, size - 3 }, { 1, 8, 8, size - 2 }, { 0, 8, 8, size - 1 } };
     for (var i = 0; i < 15; i++)
     {
         var p1 = new Point(modules[i, 0], modules[i, 1]);
         var p2 = new Point(modules[i, 2], modules[i, 3]);
         qrCode.ModuleMatrix[p1.Y][p1.X] = fStr[i] == '1';
         qrCode.ModuleMatrix[p2.Y][p2.X] = fStr[i] == '1';
     }
 }
Exemplo n.º 19
0
 public static void AddQuietZone(ref QRCodeData qrCode)
 {
     var quietLine = new bool[qrCode.ModuleMatrix.Count + 8];
     for (var i = 0; i < quietLine.Length; i++)
         quietLine[i] = false;
     for (var i = 0; i < 4; i++)
         qrCode.ModuleMatrix.Insert(0, new BitArray(quietLine));
     for (var i = 0; i < 4; i++)
         qrCode.ModuleMatrix.Add(new BitArray(quietLine));
     for (var i = 4; i < qrCode.ModuleMatrix.Count - 4; i++)
     {
         bool[] quietPart = { false, false, false, false };
         var tmpLine = new List<bool>(quietPart);
         tmpLine.AddRange(qrCode.ModuleMatrix[i].Cast<bool>());
         tmpLine.AddRange(quietPart);
         qrCode.ModuleMatrix[i] = new BitArray(tmpLine.ToArray());
     }
 }
Exemplo n.º 20
0
            public static void PlaceVersion(ref QRCodeData qrCode, string versionStr)
            {
                var size = qrCode.ModuleMatrix.Count;
                var vStr = new string(versionStr.Reverse().ToArray());

                for (var x = 0; x < 6; x++)
                {
                    for (var y = 0; y < 3; y++)
                    {
                        qrCode.ModuleMatrix[y + size - 11][x] = vStr[x * 3 + y] == '1';
                        qrCode.ModuleMatrix[x][y + size - 11] = vStr[x * 3 + y] == '1';
                    }
                }
            }
Exemplo n.º 21
0
 /// <summary>
 /// Set a QRCodeData object that will be used to generate QR code. Used in COM Objects connections
 /// </summary>
 /// <param name="data">Need a QRCodeData object generated by QRCodeGenerator.CreateQrCode()</param>
 virtual public void SetQRCodeData(QRCodeData data)
 {
     this.QrCodeData = data;
 }
Exemplo n.º 22
0
        public QRCodeData CreateQrCode(string plainText, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false)
        {
            var encoding = this.GetEncodingFromPlaintext(plainText);
            var codedText = this.PlainTextToBinary(plainText, encoding, utf8BOM, forceUtf8);
            var dataInputLength = this.GetDataLength(encoding, plainText, codedText, forceUtf8);
            var version = this.GetVersion(dataInputLength, encoding, eccLevel);

            var modeIndicator = DecToBin((int)encoding, 4);
            var countIndicator = DecToBin(dataInputLength, this.GetCountIndicatorLength(version, encoding));
            var bitString = modeIndicator + countIndicator;

            bitString += codedText;

            //Fill up data code word
            var eccInfo = this.capacityECCTable.Single(x => x.Version == version && x.ErrorCorrectionLevel.Equals(eccLevel));
            var dataLength = eccInfo.TotalDataCodewords * 8;
            var lengthDiff = dataLength - bitString.Length;
            if (lengthDiff > 0)
                bitString += new string('0', Math.Min(lengthDiff, 4));
            if ((bitString.Length % 8) != 0)
                bitString += new string('0', 8 - (bitString.Length % 8));
            while (bitString.Length < dataLength)
                bitString += "1110110000010001";
            if (bitString.Length > dataLength)
                bitString = bitString.Substring(0, dataLength);

            //Calculate error correction words
            var codeWordWithECC = new List<CodewordBlock>();
            for (var i = 0; i < eccInfo.BlocksInGroup1; i++)
            {
                var bitStr = bitString.Substring(i * eccInfo.CodewordsInGroup1 * 8, eccInfo.CodewordsInGroup1 * 8);
                var bitBlockList = this.BinaryStringToBitBlockList(bitStr);
                var bitBlockListDec = this.BinaryStringListToDecList(bitBlockList);
                var eccWordList = this.CalculateECCWords(bitStr, eccInfo);
                var eccWordListDec = this.BinaryStringListToDecList(eccWordList);
                codeWordWithECC.Add(
                    new CodewordBlock(1,
                                      i + 1,
                                      bitStr,
                                      bitBlockList,
                                      eccWordList,
                                      bitBlockListDec,
                                      eccWordListDec)
                                );
            }
            bitString = bitString.Substring(eccInfo.BlocksInGroup1 * eccInfo.CodewordsInGroup1 * 8);
            for (var i = 0; i < eccInfo.BlocksInGroup2; i++)
            {
                var bitStr = bitString.Substring(i * eccInfo.CodewordsInGroup2 * 8, eccInfo.CodewordsInGroup2 * 8);
                var bitBlockList = this.BinaryStringToBitBlockList(bitStr);
                var bitBlockListDec = this.BinaryStringListToDecList(bitBlockList);
                var eccWordList = this.CalculateECCWords(bitStr, eccInfo);
                var eccWordListDec = this.BinaryStringListToDecList(eccWordList);
                codeWordWithECC.Add(new CodewordBlock(2,
                                      i + 1,
                                      bitStr,
                                      bitBlockList,
                                      eccWordList,
                                      bitBlockListDec,
                                      eccWordListDec)
                                );
            }

            //Interleave code words
            var interleavedWordsSb = new StringBuilder();
            for (var i = 0; i < Math.Max(eccInfo.CodewordsInGroup1, eccInfo.CodewordsInGroup2); i++)
            {
                foreach (var codeBlock in codeWordWithECC)
                    if (codeBlock.CodeWords.Count > i)
                        interleavedWordsSb.Append(codeBlock.CodeWords[i]);
            }

            for (var i = 0; i < eccInfo.ECCPerBlock; i++)
            {
                foreach (var codeBlock in codeWordWithECC)
                    if (codeBlock.ECCWords.Count > i)
                        interleavedWordsSb.Append(codeBlock.ECCWords[i]);
            }
            interleavedWordsSb.Append(new string('0', this.remainderBits[version - 1]));
            var interleavedData = interleavedWordsSb.ToString();

            //Place interleaved data on module matrix
            var qr = new QRCodeData(version);
            var blockedModules = new List<Rectangle>();
            ModulePlacer.PlaceFinderPatterns(ref qr, ref blockedModules);
            ModulePlacer.ReserveSeperatorAreas(qr.ModuleMatrix.Count, ref blockedModules);
            ModulePlacer.PlaceAlignmentPatterns(ref qr, this.alignmentPatternTable.Where(x => x.Version == version).Select(x => x.PatternPositions).First(), ref blockedModules);
            ModulePlacer.PlaceTimingPatterns(ref qr, ref blockedModules);
            ModulePlacer.PlaceDarkModule(ref qr, version, ref blockedModules);
            ModulePlacer.ReserveVersionAreas(qr.ModuleMatrix.Count, version, ref blockedModules);
            ModulePlacer.PlaceDataWords(ref qr, interleavedData, ref blockedModules);
            var maskVersion = ModulePlacer.MaskCode(ref qr, version, ref blockedModules, eccLevel);
            var formatStr = GetFormatString(eccLevel, maskVersion);

            ModulePlacer.PlaceFormat(ref qr, formatStr);
            if (version >= 7)
            {
                var versionString = GetVersionString(version);
                ModulePlacer.PlaceVersion(ref qr, versionString);
            }

            ModulePlacer.AddQuietZone(ref qr);
            return qr;
        }
Exemplo n.º 23
0
 public PngByteQRCode(QRCodeData data) : base(data)
 {
 }
Exemplo n.º 24
0
 public BitmapByteQRCode(QRCodeData data) : base(data)
 {
 }
Exemplo n.º 25
0
 public PostscriptQRCode(QRCodeData data) : base(data)
 {
 }
Exemplo n.º 26
0
 /// <summary>
 /// Creates new ArtQrCode object
 /// </summary>
 /// <param name="data">QRCodeData generated by the QRCodeGenerator</param>
 public ArtQRCode(QRCodeData data) : base(data)
 {
 }
Exemplo n.º 27
0
            public static int MaskCode(ref QRCodeData qrCode, int version, ref List<Rectangle> blockedModules, ECCLevel eccLevel)
            {
                var patternName = string.Empty;
                var patternScore = 0;

                var size = qrCode.ModuleMatrix.Count;

                foreach (var pattern in typeof(MaskPattern).GetMethods())
                {
                    if (pattern.Name.Length == 8 && pattern.Name.Substring(0, 7) == "Pattern")
                    {
                        var qrTemp = new QRCodeData(version);
                        for (var y = 0; y < size; y++)
                        {
                            for (var x = 0; x < size; x++)
                            {
                                qrTemp.ModuleMatrix[y][x] = qrCode.ModuleMatrix[y][x];
                            }

                        }

                        var formatStr = GetFormatString(eccLevel, Convert.ToInt32((pattern.Name.Substring(7, 1)))-1);
                        ModulePlacer.PlaceFormat(ref qrTemp, formatStr);
                        if (version >= 7)
                        {
                            var versionString = GetVersionString(version);
                            ModulePlacer.PlaceVersion(ref qrTemp, versionString);
                        }

                        for (var x = 0; x < size; x++)
                        {
                            for (var y = 0; y < size; y++)
                            {
                                if (!IsBlocked(new Rectangle(x, y, 1, 1), blockedModules))
                                {
                                    qrTemp.ModuleMatrix[y][x] ^= (bool)pattern.Invoke(null, new object[] { x, y });
                                }
                            }
                        }

                        var score = MaskPattern.Score(ref qrTemp);
                        if (string.IsNullOrEmpty(patternName) || patternScore > score)
                        {
                            patternName = pattern.Name;
                            patternScore = score;
                        }

                    }
                }

                var patterMethod = typeof(MaskPattern).GetMethods().First(x => x.Name == patternName);
                for (var x = 0; x < size; x++)
                {
                    for (var y = 0; y < size; y++)
                    {
                        if (!IsBlocked(new Rectangle(x, y, 1, 1), blockedModules))
                        {
                            qrCode.ModuleMatrix[y][x] ^= (bool)patterMethod.Invoke(null, new object[] { x, y });
                        }
                    }
                }
                return Convert.ToInt32(patterMethod.Name.Substring(patterMethod.Name.Length - 1, 1)) - 1;
            }
Exemplo n.º 28
0
 public AsciiQRCode(QRCodeData data) : base(data)
 {
 }
Exemplo n.º 29
0
            public static void PlaceAlignmentPatterns(ref QRCodeData qrCode, List<Point> alignmentPatternLocations, ref List<Rectangle> blockedModules)
            {
                foreach (var loc in alignmentPatternLocations)
                {
                    var alignmentPatternRect = new Rectangle(loc.X, loc.Y, 5, 5);
                    var blocked = false;
                    foreach (var blockedRect in blockedModules)
                    {
                        if (Intersects(alignmentPatternRect, blockedRect))
                        {
                            blocked = true;
                            break;
                        }
                    }
                    if (blocked)
                        continue;

                    for (var x = 0; x < 5; x++)
                    {
                        for (var y = 0; y < 5; y++)
                        {
                            if (y == 0 || y == 4 || x == 0 || x == 4 || (x == 2 && y == 2))
                            {
                                qrCode.ModuleMatrix[loc.Y + y][loc.X + x] = true;
                            }
                        }
                    }
                    blockedModules.Add(new Rectangle(loc.X, loc.Y, 5, 5));
                }
            }
Exemplo n.º 30
0
 public override void SetQRCodeData(QRCodeData data)
 {
     this.qr.SetQRCodeData(data);
 }
Exemplo n.º 31
0
 public static void PlaceDarkModule(ref QRCodeData qrCode, int version, ref List<Rectangle> blockedModules)
 {
     qrCode.ModuleMatrix[4 * version + 9][8] = true;
     blockedModules.Add(new Rectangle(8, 4 * version + 9, 1, 1));
 }