Search in sources :

Example 6 with Version

use of com.google.zxing.qrcode.decoder.Version in project zxing by zxing.

the class Encoder method recommendVersion.

/**
   * Decides the smallest version of QR code that will contain all of the provided data.
   *
   * @throws WriterException if the data cannot fit in any version
   */
private static Version recommendVersion(ErrorCorrectionLevel ecLevel, Mode mode, BitArray headerBits, BitArray dataBits) throws WriterException {
    // Hard part: need to know version to know how many bits length takes. But need to know how many
    // bits it takes to know version. First we take a guess at version by assuming version will be
    // the minimum, 1:
    int provisionalBitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, Version.getVersionForNumber(1));
    Version provisionalVersion = chooseVersion(provisionalBitsNeeded, ecLevel);
    // Use that guess to calculate the right version. I am still not sure this works in 100% of cases.
    int bitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, provisionalVersion);
    return chooseVersion(bitsNeeded, ecLevel);
}
Also used : Version(com.google.zxing.qrcode.decoder.Version)

Aggregations

Version (com.google.zxing.qrcode.decoder.Version)6 NotFoundException (com.google.zxing.NotFoundException)2 ResultPoint (com.google.zxing.ResultPoint)2 WriterException (com.google.zxing.WriterException)2 BitArray (com.google.zxing.common.BitArray)2 BitMatrix (com.google.zxing.common.BitMatrix)2 CharacterSetECI (com.google.zxing.common.CharacterSetECI)2 DetectorResult (com.google.zxing.common.DetectorResult)2 PerspectiveTransform (com.google.zxing.common.PerspectiveTransform)2 Mode (com.google.zxing.qrcode.decoder.Mode)2