ZXing.QrCode.Internal.Version.decodeVersionInformation C# (CSharp) Méthode

decodeVersionInformation() static private méthode

static private decodeVersionInformation ( int versionBits ) : Version
versionBits int
Résultat Version
        internal static Version decodeVersionInformation(int versionBits)
        {
            int bestDifference = Int32.MaxValue;
             int bestVersion = 0;
             for (int i = 0; i < VERSION_DECODE_INFO.Length; i++)
             {
            int targetVersion = VERSION_DECODE_INFO[i];
            // Do the version info bits match exactly? done.
            if (targetVersion == versionBits)
            {
               return getVersionForNumber(i + 7);
            }
            // Otherwise see if this is the closest to a real version info bit string
            // we have seen so far
            int bitsDifference = FormatInformation.numBitsDiffering(versionBits, targetVersion);
            if (bitsDifference < bestDifference)
            {
               bestVersion = i + 7;
               bestDifference = bitsDifference;
            }
             }
             // We can tolerate up to 3 bits of error since no two version info codewords will
             // differ in less than 8 bits.
             if (bestDifference <= 3)
             {
            return getVersionForNumber(bestVersion);
             }
             // If we didn't find a close enough match, fail
             return null;
        }

Usage Example

Exemple #1
0
        /// <summary> <p>Reads version information from one of its two locations within the QR Code.</p>
        ///
        /// </summary>
        /// <returns> {@link Version} encapsulating the QR Code's version
        /// </returns>
        /// <throws>  ReaderException if both version information locations cannot be parsed as </throws>
        /// <summary> the valid encoding of version information
        /// </summary>
        internal Version readVersion()
        {
            if (parsedVersion != null)
            {
                return(parsedVersion);
            }

            int dimension = bitMatrix.Height;

            int provisionalVersion = (dimension - 17) >> 2;

            if (provisionalVersion <= 6)
            {
                return(Version.getVersionForNumber(provisionalVersion));
            }

            // Read top-right version info: 3 wide by 6 tall
            int versionBits = 0;
            int ijMin       = dimension - 11;

            for (int j = 5; j >= 0; j--)
            {
                for (int i = dimension - 9; i >= ijMin; i--)
                {
                    versionBits = copyBit(i, j, versionBits);
                }
            }

            parsedVersion = Version.decodeVersionInformation(versionBits);
            if (parsedVersion != null && parsedVersion.DimensionForVersion == dimension)
            {
                return(parsedVersion);
            }

            // Hmm, failed. Try bottom left: 6 wide by 3 tall
            versionBits = 0;
            for (int i = 5; i >= 0; i--)
            {
                for (int j = dimension - 9; j >= ijMin; j--)
                {
                    versionBits = copyBit(i, j, versionBits);
                }
            }

            parsedVersion = Version.decodeVersionInformation(versionBits);
            if (parsedVersion != null && parsedVersion.DimensionForVersion == dimension)
            {
                return(parsedVersion);
            }
            return(null);
        }