Ejemplo n.º 1
0
        // Initialize "qrCode" according to "numInputBytes", "ecLevel", and "mode". On success, modify
        // "qrCode".
        private static void initQRCode(int numInputBytes, ErrorCorrectionLevel ecLevel, Mode mode, QRCode qrCode)
        {
            try
            {
                qrCode.setECLevel(ecLevel);
                qrCode.setMode(mode);

                // In the following comments, we use numbers of Version 7-H.
                for (int versionNum = 1; versionNum <= 40; versionNum++)
                {
                    Version version = Version.getVersionForNumber(versionNum);
                    // numBytes = 196
                    int numBytes = version.getTotalCodewords();
                    // getNumECBytes = 130
                    Version.ECBlocks ecBlocks = version.getECBlocksForLevel(ecLevel);
                    int numEcBytes            = ecBlocks.getTotalECCodewords();
                    // getNumRSBlocks = 5
                    int numRSBlocks = ecBlocks.getNumBlocks();
                    // getNumDataBytes = 196 - 130 = 66
                    int 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?)");
            }
            catch (Exception e) {
                throw new WriterException(e.Message);
            }
        }
Ejemplo n.º 2
0
        // Initialize "qrCode" according to "numInputBytes", "ecLevel", and "mode". On success, modify
        // "qrCode".
        private static void initQRCode(int numInputBytes, ErrorCorrectionLevel ecLevel, Mode mode, QRCode qrCode)
        {
            try
              {
                qrCode.setECLevel(ecLevel);
                qrCode.setMode(mode);

                // In the following comments, we use numbers of Version 7-H.
                for (int versionNum = 1; versionNum <= 40; versionNum++) {
                  Version version = Version.getVersionForNumber(versionNum);
                  // numBytes = 196
                  int numBytes = version.getTotalCodewords();
                  // getNumECBytes = 130
                  Version.ECBlocks ecBlocks = version.getECBlocksForLevel(ecLevel);
                  int numEcBytes = ecBlocks.getTotalECCodewords();
                  // getNumRSBlocks = 5
                  int numRSBlocks = ecBlocks.getNumBlocks();
                  // getNumDataBytes = 196 - 130 = 66
                  int 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?)");
              }
              catch(Exception e){
                throw new WriterException(e.Message);
              }
        }