Beispiel #1
0
        internal static ErrorCorrectionInfo GetErrorCorrectionInfo(int inputBytes, ErrorCorrectionLevel desiredLevel, out int qrCodeVersion, out ErrorCorrectionLevel qrErrorCorrectionLevel)
        {
            for (int i = 0; i < _versions.Length; i++)
            {
                QRVersion version = _versions[i];
                if (version.GetCorrectionInfo(desiredLevel).TotalDataBytes >= inputBytes)
                {
                    // Found match, now get highest correction code within this version that can still hold desired number of bytes.
                    qrCodeVersion = i + 1;
                    if (version.H.TotalDataBytes >= inputBytes)
                    {
                        qrErrorCorrectionLevel = ErrorCorrectionLevel.H; return(version.H);
                    }
                    else if (version.Q.TotalDataBytes >= inputBytes)
                    {
                        qrErrorCorrectionLevel = ErrorCorrectionLevel.Q; return(version.Q);
                    }
                    else if (version.M.TotalDataBytes >= inputBytes)
                    {
                        qrErrorCorrectionLevel = ErrorCorrectionLevel.M; return(version.M);
                    }
                    else
                    {
                        qrErrorCorrectionLevel = ErrorCorrectionLevel.L; return(version.L);
                    }
                }
            }

            throw new InputTooLongException();
        }