public void GenerateBytesToWrite(byte[] bytesToCode) { Service = QRPayloadLengthForVerAndCLvl.GetServiceInformationForDataLength(bytesToCode.Length * 8, QRCodeServiceInformation.CorrectionLvl.H); bool[] allBits = GetQRBits(bytesToCode); byte[] allBytes = BitsToBytes(allBits); byte[][] allBlocks = CreateQRBlocks(allBytes); byte[][] correctionBytes = CreateCorrectionBytes(allBlocks); ToWrite = AlternatelyCombining(allBlocks, correctionBytes); Console.WriteLine("Service: " + Service); Console.WriteLine("ToWrite: " + ToWrite.Length); }
public void WriteQRCode(QRCodeServiceInformation _service, byte[] _toWrite) { Service = _service; ToWrite = _toWrite; int[] levelingPatterns = Service.Version > 1 ? Tables.QRLevelingPatternsForVer.LevelingPatterns(Service.Version) : new int[0]; int side = Service.Version > 1 ? levelingPatterns.Last() + 7 : 21;//длина строны QR кода QRGrid = new int[side][]; for (int i = 0; i < side; i++) { QRGrid[i] = Enumerable.Repeat <int>(7, side).ToArray(); } SetFindPatterns(); SetSyncStrips(); QRGrid[QRGrid.Length - 8][8] = 1; SetAlignmentPatterns(levelingPatterns); if (Service.Version >= 7) { SetVersionCode(Service.Version); } dataWritedPoints = new HashSet <Point>(); int[] scoresWithMasks = new int[8]; for (int i = 0; i < scoresWithMasks.Length; i++) { SetMaskAndCLvl(i); WriteDataWithMask(Tables.MaskTable.Mask(i)); scoresWithMasks[i] = CalculateScores(); } Console.WriteLine(string.Join(" ", scoresWithMasks)); int minIndex = scoresWithMasks.ToList().IndexOf(scoresWithMasks.Min()); SetMaskAndCLvl(minIndex); WriteDataWithMask(Tables.MaskTable.Mask(minIndex)); QRCodeSaver.Save(QRGrid, 5, Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @$ "\result.jpg"); }
public QRCodeWriter(QRCodeServiceInformation _service, byte[] _toWrite) { WriteQRCode(_service, _toWrite); }