예제 #1
0
        public static QREncoderMatrix Encode(string content, QRCorrectionLevel correctionLevel)
        {
            string encoding = DEFAULT_ENCODING;

            QRMode mode = chooseMode(content, encoding);

            BitList header = new BitList();

            header.AppendBits(mode.ModeSignature, 4);

            BitList data = new BitList();

            AppendBytes(content, mode, data);

            int       provisionalBitsNeeded = header.Size + mode.GetVersionCharacterCount(QRVersion.GetVersionByNumber(1)) + data.Size;
            QRVersion provisionalVersion    = chooseVersion(provisionalBitsNeeded, correctionLevel);

            int       bitsNeeded = header.Size + mode.GetVersionCharacterCount(provisionalVersion) + data.Size;
            QRVersion version    = chooseVersion(bitsNeeded, correctionLevel);

            BitList headerNData = new BitList();

            headerNData.AppendBitList(header);

            int numLetters = mode == QRMode.BYTE ? data.ByteSize : content.Length;

            AppendLengthInfo(numLetters, version, mode, headerNData);

            headerNData.AppendBitList(data);

            QRVersion.CorrectionBlockSet correctionBlockSet = version.GetBlockSetByLevel(correctionLevel);
            int dataBytesQty = version.TotalCodewords - correctionBlockSet.TotalCodewords;

            WriteTerminationSection(dataBytesQty, headerNData);

            BitList finalBits = MixWithCorrectionBytes(headerNData, version.TotalCodewords, dataBytesQty, correctionBlockSet.TotalQty);

            int             dimension = version.Dimension;
            QREncoderMatrix matrix    = new QREncoderMatrix(dimension, content, correctionLevel, mode, version);

            int maskPattern = chooseMaskPattern(finalBits, correctionLevel, version, matrix);

            matrix.MaskPattern = maskPattern;

            matrix.FormMatrix(finalBits, correctionLevel, version, maskPattern);

            return(matrix);
        }
예제 #2
0
        public static QREncoderMatrix CreateMatrix(string content, QRCorrectionLevel correctionLevel)
        {
            QREncoderMatrix matrix = Encode(content, correctionLevel);

            return(matrix);
        }