public static GetVersionForNumber ( int versionNumber ) : Version | ||
versionNumber | int | |
return | Version |
/** * Append length info. On success, store the result in "bits". */ private static void AppendLengthInfo(int numLetters, int version, Mode mode, BitVector bits) { var numBits = mode.GetCharacterCountBits(Version.GetVersionForNumber(version)); if (numLetters > ((1 << numBits) - 1)) { throw new WriterException(numLetters + "is bigger than" + ((1 << numBits) - 1)); } bits.AppendBits(numLetters, numBits); }
/** * Initialize "qrCode" according to "numInputBytes", "ecLevel", and "mode". On success, * modify "qrCode". */ private static void InitQRCode(int numInputBytes, ErrorCorrectionLevel ecLevel, Mode mode, QRCode qrCode) { qrCode.SetECLevel(ecLevel); qrCode.SetMode(mode); // In the following comments, we use numbers of Version 7-H. for (var versionNum = 1; versionNum <= 40; versionNum++) { var version = Version.GetVersionForNumber(versionNum); // numBytes = 196 var numBytes = version.GetTotalCodewords(); // getNumECBytes = 130 var ecBlocks = version.GetECBlocksForLevel(ecLevel); var numEcBytes = ecBlocks.GetTotalECCodewords(); // getNumRSBlocks = 5 var numRSBlocks = ecBlocks.GetNumBlocks(); // getNumDataBytes = 196 - 130 = 66 var numDataBytes = numBytes - numEcBytes; // We want to choose the smallest version which can contain data of "numInputBytes" + some // extra bits for the header (mode info and length info). The header can be three bytes // (precisely 4 + 16 bits) at most. Hence we do +3 here. if (numDataBytes >= numInputBytes + 3) { // Yay, we found the proper rs block info! qrCode.SetVersion(versionNum); qrCode.SetNumTotalBytes(numBytes); qrCode.SetNumDataBytes(numDataBytes); qrCode.SetNumRSBlocks(numRSBlocks); // getNumECBytes = 196 - 66 = 130 qrCode.SetNumECBytes(numEcBytes); // matrix width = 21 + 6 * 4 = 45 qrCode.SetMatrixWidth(version.GetDimensionForVersion()); return; } } throw new WriterException("Cannot find proper rs block info (input data too big?)"); }