Exemplo n.º 1
0
        private byte[] CreateData(int errorCorrectLevel)
        {
            RSBlock[] rsBlocks = RSBlock.GetRSBlocks(errorCorrectLevel);

            BitBuffer buffer = new BitBuffer();

            buffer.Put(4, 4);
            buffer.Put(qrData.Length, 8);
            for (int i = 0; i < qrData.Length; i++)
            {
                buffer.Put(qrData[i], 8);
            }

            int totalDataCount = 0;

            for (int i = 0; i < rsBlocks.Length; i++)
            {
                totalDataCount += rsBlocks[i].GetDataCount();
            }

            if (buffer.GetLengthInBits() > totalDataCount * 8)
            {
                throw new ArgumentException("String length overflow. ("
                                            + buffer.GetLengthInBits()
                                            + ">"
                                            + totalDataCount * 8
                                            + ")");
            }

            if (buffer.GetLengthInBits() + 4 <= totalDataCount * 8)
            {
                buffer.Put(0, 4);
            }

            // padding
            while (buffer.GetLengthInBits() % 8 != 0)
            {
                buffer.Put(false);
            }

            // padding
            while (true)
            {
                if (buffer.GetLengthInBits() >= totalDataCount * 8)
                {
                    break;
                }
                buffer.Put(PAD0, 8);

                if (buffer.GetLengthInBits() >= totalDataCount * 8)
                {
                    break;
                }
                buffer.Put(PAD1, 8);
            }

            return(CreateBytes(buffer, rsBlocks));
        }
Exemplo n.º 2
0
        private byte[] CreateData(int errorCorrectLevel)
        {
            RSBlock[] rSBlocks  = RSBlock.GetRSBlocks(errorCorrectLevel);
            BitBuffer bitBuffer = new BitBuffer();

            bitBuffer.Put(4, 4);
            bitBuffer.Put(this.qrData.Length, 8);
            for (int i = 0; i < this.qrData.Length; i++)
            {
                bitBuffer.Put((int)this.qrData[i], 8);
            }
            int num = 0;

            for (int j = 0; j < rSBlocks.Length; j++)
            {
                num += rSBlocks[j].GetDataCount();
            }
            if (bitBuffer.GetLengthInBits() > num * 8)
            {
                throw new ArgumentException(string.Concat(new object[]
                {
                    "String length overflow. (",
                    bitBuffer.GetLengthInBits(),
                    ">",
                    num * 8,
                    ")"
                }));
            }
            if (bitBuffer.GetLengthInBits() + 4 <= num * 8)
            {
                bitBuffer.Put(0, 4);
            }
            while (bitBuffer.GetLengthInBits() % 8 != 0)
            {
                bitBuffer.Put(false);
            }
            while (bitBuffer.GetLengthInBits() < num * 8)
            {
                bitBuffer.Put(236, 8);
                if (bitBuffer.GetLengthInBits() >= num * 8)
                {
                    break;
                }
                bitBuffer.Put(17, 8);
            }
            return(QRCode.CreateBytes(bitBuffer, rSBlocks));
        }
Exemplo n.º 3
0
        private byte[] CreateData(int errorCorrectLevel)
        {
            RSBlock[] rsBlocks = RSBlock.GetRSBlocks(errorCorrectLevel);

            BitBuffer buffer = new BitBuffer();
            buffer.Put(4, 4);
            buffer.Put(qrData.Length, 8);
            for (int i = 0; i < qrData.Length; i++) {
            buffer.Put(qrData[i], 8);
            }

            int totalDataCount = 0;
            for (int i = 0; i < rsBlocks.Length; i++) {
            totalDataCount += rsBlocks[i].GetDataCount();
            }

            if (buffer.GetLengthInBits() > totalDataCount * 8) {
            throw new ArgumentException("String length overflow. ("
                + buffer.GetLengthInBits()
                + ">"
                +  totalDataCount * 8
                + ")");
            }

            if (buffer.GetLengthInBits() + 4 <= totalDataCount * 8) {
            buffer.Put(0, 4);
            }

            // padding
            while (buffer.GetLengthInBits() % 8 != 0) {
            buffer.Put(false);
            }

            // padding
            while (true) {
            if (buffer.GetLengthInBits() >= totalDataCount * 8) {
                break;
            }
            buffer.Put(PAD0, 8);

            if (buffer.GetLengthInBits() >= totalDataCount * 8) {
                break;
            }
            buffer.Put(PAD1, 8);
            }

            return CreateBytes(buffer, rsBlocks);
        }