private string GetFormatString(ECCLevel level, int maskVersion) { var generator = "10100110111"; const string fStrMask = "101010000010010"; var fStr = (level == ECCLevel.L) ? "01" : (level == ECCLevel.M) ? "00" : (level == ECCLevel.Q) ? "11" : "10"; fStr += DecToBin(maskVersion, 3); var fStrEcc = fStr.PadRight(15, '0').TrimStart('0'); while (fStrEcc.Length > 10) { var sb = new StringBuilder(); generator = generator.PadRight(fStrEcc.Length, '0'); for (var i = 0; i < fStrEcc.Length; i++) { sb.Append((Convert.ToInt32(fStrEcc[i]) ^ Convert.ToInt32(generator[i])).ToString()); } fStrEcc = sb.ToString().TrimStart('0'); } fStrEcc = fStrEcc.PadLeft(10, '0'); fStr += fStrEcc; var sbMask = new StringBuilder(); for (var i = 0; i < fStr.Length; i++) { sbMask.Append((Convert.ToInt32(fStr[i]) ^ Convert.ToInt32(fStrMask[i])).ToString()); } return(sbMask.ToString()); }
public static bool[,] GetQRArray(string plainText, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1) { using (QRCodeGenerator qrGenerator = new QRCodeGenerator()) using (QRCodeData qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion)) using (QRCode qrCode = new QRCode(qrCodeData)) return(qrCode.GetArray()); }
public static byte[] GetQRCode(string txt, ECCLevel eccLevel, int size) { using (var qrGen = new QRCodeGenerator()) using (var qrCode = qrGen.CreateQrCode(txt, eccLevel)) using (var qrPng = new PngByteQRCode(qrCode)) return(qrPng.GetGraphic(size)); }
public static Texture2D GetQRCode(string plainText, int pixelsPerModule, ECCLevel eccLevel = ECCLevel.Q, Color?darkColor = null, Color?lightColor = null, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, bool drawQuietZones = true) { using (QRCodeGenerator qrGenerator = new QRCodeGenerator()) using (QRCodeData qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion)) using (QRCode qrCode = new QRCode(qrCodeData)) return(qrCode.GetGraphic(pixelsPerModule, darkColor ?? Color.black, lightColor ?? Color.white, drawQuietZones)); }
static void SetHeader(int version, ECCLevel level) { var(eccLength, _, msgLength1, _, msgLength2) = QRInfo.GetEccInfo(version, level); int msgLength = Math.Max(msgLength1, msgLength2); if (cacheHeaders[eccLength].MaxMessageLength < msgLength) { cacheHeaders[eccLength].MaxMessageLength = msgLength; } }
public static byte[] GetQRCode(string plainText, int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1) { using (var qrGenerator = new QRCodeGenerator()) using ( var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion)) using (var qrCode = new PdfByteQRCode(qrCodeData)) return(qrCode.GetGraphic(pixelsPerModule, darkColorHtmlHex, lightColorHtmlHex)); }
/// <summary> /// 创建二维码 /// </summary> /// <param name="content">二维码内容</param> /// <param name="level"></param> /// <param name="pixelsPerModule"></param> /// <returns></returns> public static Bitmap CreateQrCode(string content, ECCLevel level = ECCLevel.Q, int pixelsPerModule = 5) { using (QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator()) { //QRCodeGenerator.ECCLevel:纠错能力,Q级:约可纠错25%的数据码字 QRCodeData qrCodeData = qrGenerator.CreateQrCode(content, level); QRCode qrcode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrcode.GetGraphic(pixelsPerModule); return(qrCodeImage); } }
public static uint GetDataBytes(QRCodeVersion version, ECCLevel eccLevel) { var cap = GetCapacity(version, eccLevel, MessageMode.EncodingMode.Byte); // TODO other modes? if (version.VersionNumber < 10u) { return(cap + 2u); // indicator nibble (+ terminator) + 8 bit length } else { return(cap + 3u); // indicator nibble (+ terminator) + 16 bit length } }
private void cmbEccLevel_SelectedIndexChanged(object sender, EventArgs e) { switch (cmbEccLevel.SelectedIndex) { case 0: eccLevel = ECCLevel.L; break; case 1: eccLevel = ECCLevel.M; break; case 2: eccLevel = ECCLevel.Q; break; case 3: eccLevel = ECCLevel.H; break; } }
private static void Encode(string text, ECCLevel ecc) { Log.Information($"encoding: {text}"); using var generator = new QRCodeGenerator(); using var qr = generator.CreateQrCode(text, ecc); var lines = GetArrayDefinition(qr).Skip(4).Reverse().Skip(4).Reverse(); var arrayDefinition = $"qr=\n[{string.Join(",\n", lines)}];"; Log.Information(arrayDefinition); }
public QrCodeMaker(IOptions <QrCodeOptions> options) { _size = int.Parse(options.Value.Size); _darkColor = options.Value.DarkColor; _lightColor = options.Value.LightColor; _withLogo = bool.Parse(options.Value.WithLogo); _logoName = options.Value.LogoName; _eccLevel = options.Value.EccLevel switch { "L" => ECCLevel.L, "M" => ECCLevel.M, "Q" => ECCLevel.Q, _ => ECCLevel.H }; _generator = new QRCodeGenerator(); }
public static uint GetCapacity(QRCodeVersion version, ECCLevel eccLevel, MessageMode.EncodingMode mode) { switch (mode) { case MessageMode.EncodingMode.Numeric: return(numeric_capacity[(int)eccLevel, version.VersionNumber - 1]); case MessageMode.EncodingMode.Alphanumeric: return(alphanumeric_capacity[(int)eccLevel, version.VersionNumber - 1]); case MessageMode.EncodingMode.Byte: return(bytemode_capacity[(int)eccLevel, version.VersionNumber - 1]); case MessageMode.EncodingMode.Kanji: return(kanji_capacity[(int)eccLevel, version.VersionNumber - 1]); default: throw new ArgumentException("Invalid MessageMode", "mode"); } }
public static int MaskCode(ref QRCodeData qrCode, int version, ref List<Rectangle> blockedModules, ECCLevel eccLevel) { var patternName = string.Empty; var patternScore = 0; var size = qrCode.ModuleMatrix.Count; foreach (var pattern in typeof(MaskPattern).GetMethods()) { if (pattern.Name.Length == 8 && pattern.Name.Substring(0, 7) == "Pattern") { var qrTemp = new QRCodeData(version); for (var y = 0; y < size; y++) { for (var x = 0; x < size; x++) { qrTemp.ModuleMatrix[y][x] = qrCode.ModuleMatrix[y][x]; } } var formatStr = GetFormatString(eccLevel, Convert.ToInt32((pattern.Name.Substring(7, 1)))-1); ModulePlacer.PlaceFormat(ref qrTemp, formatStr); if (version >= 7) { var versionString = GetVersionString(version); ModulePlacer.PlaceVersion(ref qrTemp, versionString); } for (var x = 0; x < size; x++) { for (var y = 0; y < size; y++) { if (!IsBlocked(new Rectangle(x, y, 1, 1), blockedModules)) { qrTemp.ModuleMatrix[y][x] ^= (bool)pattern.Invoke(null, new object[] { x, y }); } } } var score = MaskPattern.Score(ref qrTemp); if (string.IsNullOrEmpty(patternName) || patternScore > score) { patternName = pattern.Name; patternScore = score; } } } var patterMethod = typeof(MaskPattern).GetMethods().First(x => x.Name == patternName); for (var x = 0; x < size; x++) { for (var y = 0; y < size; y++) { if (!IsBlocked(new Rectangle(x, y, 1, 1), blockedModules)) { qrCode.ModuleMatrix[y][x] ^= (bool)patterMethod.Invoke(null, new object[] { x, y }); } } } return Convert.ToInt32(patterMethod.Name.Substring(patterMethod.Name.Length - 1, 1)) - 1; }
public static string GetQRCode(string plainText, int pointsPerModule, string darkColorHex, string lightColorHex, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, bool drawQuietZones = true, bool epsFormat = false) { using (var qrGenerator = new QRCodeGenerator()) using (var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion)) using (var qrCode = new PostscriptQRCode(qrCodeData)) return(qrCode.GetGraphic(pointsPerModule, darkColorHex, lightColorHex, drawQuietZones, epsFormat)); }
public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorHex, string lightColorHex, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, bool drawQuietZones = true, SizingMode sizingMode = SizingMode.WidthHeightAttribute) { using (var qrGenerator = new QRCodeGenerator()) using (var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion)) using (var qrCode = new SvgQRCode(qrCodeData)) return(qrCode.GetGraphic(pixelsPerModule, darkColorHex, lightColorHex, drawQuietZones, sizingMode)); }
private int GetVersion(int length, EncodingMode encMode, ECCLevel eccLevel) { var version = _capacityTable.Where(x => x.Details.Where(y => (y.ErrorCorrectionLevel == eccLevel && y.CapacityDict[encMode] >= Convert.ToInt32(length))).Count() > 0).Select(x => new { version = x.Version, capacity = x.Details.Where(y => y.ErrorCorrectionLevel == eccLevel).Single().CapacityDict[encMode] }).Min(x => x.version); return(version); }
public static ErrorCorrectionLevel GetECCLevel(ECCLevel level, QRCodeVersion version) { switch (level) { case ECCLevel.Low: switch (version.VersionNumber) { case 1: return(new ErrorCorrectionLevel(level, 7, new ECCGroupInfo[] { new ECCGroupInfo(19, 1) })); case 2: return(new ErrorCorrectionLevel(level, 10, new ECCGroupInfo[] { new ECCGroupInfo(34, 1) })); case 3: return(new ErrorCorrectionLevel(level, 15, new ECCGroupInfo[] { new ECCGroupInfo(55, 1) })); case 4: return(new ErrorCorrectionLevel(level, 20, new ECCGroupInfo[] { new ECCGroupInfo(80, 1) })); case 5: return(new ErrorCorrectionLevel(level, 26, new ECCGroupInfo[] { new ECCGroupInfo(108, 1) })); case 6: return(new ErrorCorrectionLevel(level, 18, new ECCGroupInfo[] { new ECCGroupInfo(68, 2) })); case 7: return(new ErrorCorrectionLevel(level, 20, new ECCGroupInfo[] { new ECCGroupInfo(78, 2) })); case 8: return(new ErrorCorrectionLevel(level, 24, new ECCGroupInfo[] { new ECCGroupInfo(97, 2) })); case 9: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(116, 2) })); case 10: return(new ErrorCorrectionLevel(level, 18, new ECCGroupInfo[] { new ECCGroupInfo(68, 2), new ECCGroupInfo(69, 2) })); case 11: return(new ErrorCorrectionLevel(level, 20, new ECCGroupInfo[] { new ECCGroupInfo(81, 4) })); case 12: return(new ErrorCorrectionLevel(level, 24, new ECCGroupInfo[] { new ECCGroupInfo(92, 2), new ECCGroupInfo(93, 2) })); case 13: return(new ErrorCorrectionLevel(level, 26, new ECCGroupInfo[] { new ECCGroupInfo(107, 4) })); case 14: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(115, 3), new ECCGroupInfo(116, 1) })); case 15: return(new ErrorCorrectionLevel(level, 22, new ECCGroupInfo[] { new ECCGroupInfo(87, 5), new ECCGroupInfo(88, 1) })); case 16: return(new ErrorCorrectionLevel(level, 24, new ECCGroupInfo[] { new ECCGroupInfo(98, 5), new ECCGroupInfo(99, 1) })); case 17: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(107, 1), new ECCGroupInfo(108, 5) })); case 18: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(120, 5), new ECCGroupInfo(121, 1) })); case 19: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(113, 3), new ECCGroupInfo(114, 4) })); case 20: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(107, 3), new ECCGroupInfo(108, 5) })); case 21: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(116, 4), new ECCGroupInfo(117, 4) })); case 22: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(111, 2), new ECCGroupInfo(112, 7) })); case 23: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(121, 4), new ECCGroupInfo(122, 5) })); case 24: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(117, 6), new ECCGroupInfo(118, 4) })); case 25: return(new ErrorCorrectionLevel(level, 26, new ECCGroupInfo[] { new ECCGroupInfo(106, 8), new ECCGroupInfo(107, 4) })); case 26: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(114, 10), new ECCGroupInfo(115, 2) })); case 27: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(122, 8), new ECCGroupInfo(123, 4) })); case 28: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(117, 3), new ECCGroupInfo(118, 10) })); case 29: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(116, 7), new ECCGroupInfo(117, 7) })); case 30: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(115, 5), new ECCGroupInfo(116, 10) })); case 31: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(115, 13), new ECCGroupInfo(116, 3) })); case 32: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(115, 17) })); case 33: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(115, 17), new ECCGroupInfo(116, 1) })); case 34: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(115, 13), new ECCGroupInfo(116, 6) })); case 35: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(121, 12), new ECCGroupInfo(122, 7) })); case 36: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(121, 6), new ECCGroupInfo(122, 14) })); case 37: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(122, 17), new ECCGroupInfo(123, 4) })); case 38: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(122, 4), new ECCGroupInfo(123, 18) })); case 39: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(117, 20), new ECCGroupInfo(118, 4) })); case 40: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(118, 19), new ECCGroupInfo(119, 6) })); default: break; } break; case ECCLevel.Medium: switch (version.VersionNumber) { case 1: return(new ErrorCorrectionLevel(level, 10, new ECCGroupInfo[] { new ECCGroupInfo(16, 1) })); case 2: return(new ErrorCorrectionLevel(level, 16, new ECCGroupInfo[] { new ECCGroupInfo(28, 1) })); case 3: return(new ErrorCorrectionLevel(level, 26, new ECCGroupInfo[] { new ECCGroupInfo(44, 1) })); case 4: return(new ErrorCorrectionLevel(level, 18, new ECCGroupInfo[] { new ECCGroupInfo(32, 2) })); case 5: return(new ErrorCorrectionLevel(level, 24, new ECCGroupInfo[] { new ECCGroupInfo(43, 2) })); case 6: return(new ErrorCorrectionLevel(level, 16, new ECCGroupInfo[] { new ECCGroupInfo(27, 4) })); case 7: return(new ErrorCorrectionLevel(level, 18, new ECCGroupInfo[] { new ECCGroupInfo(31, 4) })); case 8: return(new ErrorCorrectionLevel(level, 22, new ECCGroupInfo[] { new ECCGroupInfo(38, 2), new ECCGroupInfo(39, 2) })); case 9: return(new ErrorCorrectionLevel(level, 22, new ECCGroupInfo[] { new ECCGroupInfo(36, 3), new ECCGroupInfo(37, 2) })); case 10: return(new ErrorCorrectionLevel(level, 26, new ECCGroupInfo[] { new ECCGroupInfo(43, 4), new ECCGroupInfo(44, 1) })); case 11: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(50, 1), new ECCGroupInfo(51, 4) })); case 12: return(new ErrorCorrectionLevel(level, 22, new ECCGroupInfo[] { new ECCGroupInfo(36, 6), new ECCGroupInfo(37, 2) })); case 13: return(new ErrorCorrectionLevel(level, 22, new ECCGroupInfo[] { new ECCGroupInfo(37, 8), new ECCGroupInfo(38, 1) })); case 14: return(new ErrorCorrectionLevel(level, 24, new ECCGroupInfo[] { new ECCGroupInfo(40, 4), new ECCGroupInfo(41, 5) })); case 15: return(new ErrorCorrectionLevel(level, 24, new ECCGroupInfo[] { new ECCGroupInfo(41, 5), new ECCGroupInfo(42, 5) })); case 16: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(45, 7), new ECCGroupInfo(46, 3) })); case 17: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(46, 10), new ECCGroupInfo(47, 1) })); case 18: return(new ErrorCorrectionLevel(level, 26, new ECCGroupInfo[] { new ECCGroupInfo(43, 9), new ECCGroupInfo(44, 4) })); case 19: return(new ErrorCorrectionLevel(level, 26, new ECCGroupInfo[] { new ECCGroupInfo(44, 3), new ECCGroupInfo(45, 11) })); case 20: return(new ErrorCorrectionLevel(level, 26, new ECCGroupInfo[] { new ECCGroupInfo(41, 3), new ECCGroupInfo(42, 13) })); case 21: return(new ErrorCorrectionLevel(level, 26, new ECCGroupInfo[] { new ECCGroupInfo(42, 17) })); case 22: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(46, 17) })); case 23: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(47, 4), new ECCGroupInfo(48, 14) })); case 24: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(45, 6), new ECCGroupInfo(46, 14) })); case 25: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(47, 8), new ECCGroupInfo(48, 13) })); case 26: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(46, 19), new ECCGroupInfo(47, 4) })); case 27: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(45, 22), new ECCGroupInfo(46, 3) })); case 28: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(45, 3), new ECCGroupInfo(46, 23) })); case 29: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(45, 21), new ECCGroupInfo(46, 7) })); case 30: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(47, 19), new ECCGroupInfo(48, 10) })); case 31: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(46, 2), new ECCGroupInfo(47, 29) })); case 32: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(46, 10), new ECCGroupInfo(47, 23) })); case 33: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(46, 14), new ECCGroupInfo(47, 21) })); case 34: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(46, 14), new ECCGroupInfo(47, 23) })); case 35: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(47, 12), new ECCGroupInfo(48, 26) })); case 36: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(47, 6), new ECCGroupInfo(48, 34) })); case 37: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(46, 29), new ECCGroupInfo(47, 14) })); case 38: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(46, 13), new ECCGroupInfo(47, 32) })); case 39: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(47, 40), new ECCGroupInfo(48, 7) })); case 40: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(47, 18), new ECCGroupInfo(48, 31) })); default: break; } break; case ECCLevel.Quartile: switch (version.VersionNumber) { case 1: return(new ErrorCorrectionLevel(level, 13, new ECCGroupInfo[] { new ECCGroupInfo(13, 1) })); case 2: return(new ErrorCorrectionLevel(level, 22, new ECCGroupInfo[] { new ECCGroupInfo(22, 1) })); case 3: return(new ErrorCorrectionLevel(level, 18, new ECCGroupInfo[] { new ECCGroupInfo(17, 2) })); case 4: return(new ErrorCorrectionLevel(level, 26, new ECCGroupInfo[] { new ECCGroupInfo(24, 2) })); case 5: return(new ErrorCorrectionLevel(level, 18, new ECCGroupInfo[] { new ECCGroupInfo(15, 2), new ECCGroupInfo(16, 2) })); case 6: return(new ErrorCorrectionLevel(level, 24, new ECCGroupInfo[] { new ECCGroupInfo(19, 4) })); case 7: return(new ErrorCorrectionLevel(level, 18, new ECCGroupInfo[] { new ECCGroupInfo(14, 2), new ECCGroupInfo(15, 4) })); case 8: return(new ErrorCorrectionLevel(level, 22, new ECCGroupInfo[] { new ECCGroupInfo(18, 4), new ECCGroupInfo(19, 2) })); case 9: return(new ErrorCorrectionLevel(level, 20, new ECCGroupInfo[] { new ECCGroupInfo(16, 4), new ECCGroupInfo(17, 4) })); case 10: return(new ErrorCorrectionLevel(level, 24, new ECCGroupInfo[] { new ECCGroupInfo(19, 6), new ECCGroupInfo(20, 2) })); case 11: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(22, 4), new ECCGroupInfo(23, 4) })); case 12: return(new ErrorCorrectionLevel(level, 26, new ECCGroupInfo[] { new ECCGroupInfo(20, 4), new ECCGroupInfo(21, 6) })); case 13: return(new ErrorCorrectionLevel(level, 24, new ECCGroupInfo[] { new ECCGroupInfo(20, 8), new ECCGroupInfo(21, 4) })); case 14: return(new ErrorCorrectionLevel(level, 20, new ECCGroupInfo[] { new ECCGroupInfo(16, 11), new ECCGroupInfo(17, 5) })); case 15: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(24, 5), new ECCGroupInfo(25, 7) })); case 16: return(new ErrorCorrectionLevel(level, 24, new ECCGroupInfo[] { new ECCGroupInfo(19, 15), new ECCGroupInfo(20, 2) })); case 17: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(22, 1), new ECCGroupInfo(23, 15) })); case 18: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(22, 17), new ECCGroupInfo(23, 1) })); case 19: return(new ErrorCorrectionLevel(level, 26, new ECCGroupInfo[] { new ECCGroupInfo(21, 17), new ECCGroupInfo(22, 4) })); case 20: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(24, 15), new ECCGroupInfo(25, 5) })); case 21: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(22, 17), new ECCGroupInfo(23, 6) })); case 22: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(24, 7), new ECCGroupInfo(25, 16) })); case 23: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(24, 11), new ECCGroupInfo(25, 14) })); case 24: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(24, 11), new ECCGroupInfo(25, 16) })); case 25: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(24, 7), new ECCGroupInfo(25, 22) })); case 26: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(22, 28), new ECCGroupInfo(23, 6) })); case 27: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(23, 8), new ECCGroupInfo(24, 26) })); case 28: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(24, 4), new ECCGroupInfo(25, 31) })); case 29: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(23, 1), new ECCGroupInfo(24, 37) })); case 30: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(24, 15), new ECCGroupInfo(25, 25) })); case 31: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(24, 42), new ECCGroupInfo(25, 1) })); case 32: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(24, 10), new ECCGroupInfo(25, 35) })); case 33: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(24, 29), new ECCGroupInfo(25, 19) })); case 34: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(24, 44), new ECCGroupInfo(25, 7) })); case 35: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(24, 39), new ECCGroupInfo(25, 14) })); case 36: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(24, 46), new ECCGroupInfo(25, 10) })); case 37: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(24, 49), new ECCGroupInfo(25, 10) })); case 38: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(24, 48), new ECCGroupInfo(25, 14) })); case 39: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(24, 43), new ECCGroupInfo(25, 22) })); case 40: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(24, 34), new ECCGroupInfo(25, 34) })); default: break; } break; case ECCLevel.High: switch (version.VersionNumber) { case 1: return(new ErrorCorrectionLevel(level, 17, new ECCGroupInfo[] { new ECCGroupInfo(9, 1) })); case 2: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(16, 1) })); case 3: return(new ErrorCorrectionLevel(level, 22, new ECCGroupInfo[] { new ECCGroupInfo(13, 2) })); case 4: return(new ErrorCorrectionLevel(level, 16, new ECCGroupInfo[] { new ECCGroupInfo(9, 4) })); case 5: return(new ErrorCorrectionLevel(level, 22, new ECCGroupInfo[] { new ECCGroupInfo(11, 2), new ECCGroupInfo(12, 2) })); case 6: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(15, 4) })); case 7: return(new ErrorCorrectionLevel(level, 26, new ECCGroupInfo[] { new ECCGroupInfo(13, 4), new ECCGroupInfo(14, 1) })); case 8: return(new ErrorCorrectionLevel(level, 26, new ECCGroupInfo[] { new ECCGroupInfo(14, 4), new ECCGroupInfo(15, 2) })); case 9: return(new ErrorCorrectionLevel(level, 24, new ECCGroupInfo[] { new ECCGroupInfo(12, 4), new ECCGroupInfo(13, 4) })); case 10: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(15, 6), new ECCGroupInfo(16, 2) })); case 11: return(new ErrorCorrectionLevel(level, 24, new ECCGroupInfo[] { new ECCGroupInfo(12, 3), new ECCGroupInfo(13, 8) })); case 12: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(14, 7), new ECCGroupInfo(15, 4) })); case 13: return(new ErrorCorrectionLevel(level, 22, new ECCGroupInfo[] { new ECCGroupInfo(11, 12), new ECCGroupInfo(12, 4) })); case 14: return(new ErrorCorrectionLevel(level, 24, new ECCGroupInfo[] { new ECCGroupInfo(12, 11), new ECCGroupInfo(13, 5) })); case 15: return(new ErrorCorrectionLevel(level, 24, new ECCGroupInfo[] { new ECCGroupInfo(12, 11), new ECCGroupInfo(13, 7) })); case 16: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(15, 3), new ECCGroupInfo(16, 13) })); case 17: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(14, 2), new ECCGroupInfo(15, 17) })); case 18: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(14, 2), new ECCGroupInfo(15, 19) })); case 19: return(new ErrorCorrectionLevel(level, 26, new ECCGroupInfo[] { new ECCGroupInfo(13, 9), new ECCGroupInfo(14, 16) })); case 20: return(new ErrorCorrectionLevel(level, 28, new ECCGroupInfo[] { new ECCGroupInfo(15, 15), new ECCGroupInfo(16, 10) })); case 21: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(16, 19), new ECCGroupInfo(17, 6) })); case 22: return(new ErrorCorrectionLevel(level, 24, new ECCGroupInfo[] { new ECCGroupInfo(13, 34) })); case 23: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(15, 16), new ECCGroupInfo(16, 14) })); case 24: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(16, 30), new ECCGroupInfo(17, 2) })); case 25: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(15, 22), new ECCGroupInfo(16, 13) })); case 26: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(16, 33), new ECCGroupInfo(17, 4) })); case 27: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(15, 12), new ECCGroupInfo(16, 28) })); case 28: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(15, 11), new ECCGroupInfo(16, 31) })); case 29: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(15, 19), new ECCGroupInfo(16, 26) })); case 30: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(15, 23), new ECCGroupInfo(16, 25) })); case 31: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(15, 23), new ECCGroupInfo(16, 28) })); case 32: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(15, 19), new ECCGroupInfo(16, 35) })); case 33: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(15, 11), new ECCGroupInfo(16, 46) })); case 34: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(16, 59), new ECCGroupInfo(17, 1) })); case 35: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(15, 22), new ECCGroupInfo(16, 41) })); case 36: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(15, 2), new ECCGroupInfo(16, 64) })); case 37: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(15, 24), new ECCGroupInfo(16, 46) })); case 38: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(15, 42), new ECCGroupInfo(16, 32) })); case 39: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(15, 10), new ECCGroupInfo(16, 67) })); case 40: return(new ErrorCorrectionLevel(level, 30, new ECCGroupInfo[] { new ECCGroupInfo(15, 20), new ECCGroupInfo(16, 61) })); default: break; } break; default: break; } throw new ArgumentException("Invalid ECCLevel or version"); }
public QRCodeData CreateQrCode(string plainText, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false) { var encoding = this.GetEncodingFromPlaintext(plainText); var codedText = this.PlainTextToBinary(plainText, encoding, utf8BOM, forceUtf8); var dataInputLength = this.GetDataLength(encoding, plainText, codedText, forceUtf8); var version = this.GetVersion(dataInputLength, encoding, eccLevel); var modeIndicator = DecToBin((int)encoding, 4); var countIndicator = DecToBin(dataInputLength, this.GetCountIndicatorLength(version, encoding)); var bitString = modeIndicator + countIndicator; bitString += codedText; //Fill up data code word var eccInfo = this.capacityECCTable.Single(x => x.Version == version && x.ErrorCorrectionLevel.Equals(eccLevel)); var dataLength = eccInfo.TotalDataCodewords * 8; var lengthDiff = dataLength - bitString.Length; if (lengthDiff > 0) bitString += new string('0', Math.Min(lengthDiff, 4)); if ((bitString.Length % 8) != 0) bitString += new string('0', 8 - (bitString.Length % 8)); while (bitString.Length < dataLength) bitString += "1110110000010001"; if (bitString.Length > dataLength) bitString = bitString.Substring(0, dataLength); //Calculate error correction words var codeWordWithECC = new List<CodewordBlock>(); for (var i = 0; i < eccInfo.BlocksInGroup1; i++) { var bitStr = bitString.Substring(i * eccInfo.CodewordsInGroup1 * 8, eccInfo.CodewordsInGroup1 * 8); var bitBlockList = this.BinaryStringToBitBlockList(bitStr); var bitBlockListDec = this.BinaryStringListToDecList(bitBlockList); var eccWordList = this.CalculateECCWords(bitStr, eccInfo); var eccWordListDec = this.BinaryStringListToDecList(eccWordList); codeWordWithECC.Add( new CodewordBlock(1, i + 1, bitStr, bitBlockList, eccWordList, bitBlockListDec, eccWordListDec) ); } bitString = bitString.Substring(eccInfo.BlocksInGroup1 * eccInfo.CodewordsInGroup1 * 8); for (var i = 0; i < eccInfo.BlocksInGroup2; i++) { var bitStr = bitString.Substring(i * eccInfo.CodewordsInGroup2 * 8, eccInfo.CodewordsInGroup2 * 8); var bitBlockList = this.BinaryStringToBitBlockList(bitStr); var bitBlockListDec = this.BinaryStringListToDecList(bitBlockList); var eccWordList = this.CalculateECCWords(bitStr, eccInfo); var eccWordListDec = this.BinaryStringListToDecList(eccWordList); codeWordWithECC.Add(new CodewordBlock(2, i + 1, bitStr, bitBlockList, eccWordList, bitBlockListDec, eccWordListDec) ); } //Interleave code words var interleavedWordsSb = new StringBuilder(); for (var i = 0; i < Math.Max(eccInfo.CodewordsInGroup1, eccInfo.CodewordsInGroup2); i++) { foreach (var codeBlock in codeWordWithECC) if (codeBlock.CodeWords.Count > i) interleavedWordsSb.Append(codeBlock.CodeWords[i]); } for (var i = 0; i < eccInfo.ECCPerBlock; i++) { foreach (var codeBlock in codeWordWithECC) if (codeBlock.ECCWords.Count > i) interleavedWordsSb.Append(codeBlock.ECCWords[i]); } interleavedWordsSb.Append(new string('0', this.remainderBits[version - 1])); var interleavedData = interleavedWordsSb.ToString(); //Place interleaved data on module matrix var qr = new QRCodeData(version); var blockedModules = new List<Rectangle>(); ModulePlacer.PlaceFinderPatterns(ref qr, ref blockedModules); ModulePlacer.ReserveSeperatorAreas(qr.ModuleMatrix.Count, ref blockedModules); ModulePlacer.PlaceAlignmentPatterns(ref qr, this.alignmentPatternTable.Where(x => x.Version == version).Select(x => x.PatternPositions).First(), ref blockedModules); ModulePlacer.PlaceTimingPatterns(ref qr, ref blockedModules); ModulePlacer.PlaceDarkModule(ref qr, version, ref blockedModules); ModulePlacer.ReserveVersionAreas(qr.ModuleMatrix.Count, version, ref blockedModules); ModulePlacer.PlaceDataWords(ref qr, interleavedData, ref blockedModules); var maskVersion = ModulePlacer.MaskCode(ref qr, version, ref blockedModules, eccLevel); var formatStr = GetFormatString(eccLevel, maskVersion); ModulePlacer.PlaceFormat(ref qr, formatStr); if (version >= 7) { var versionString = GetVersionString(version); ModulePlacer.PlaceVersion(ref qr, versionString); } ModulePlacer.AddQuietZone(ref qr); return qr; }
public static byte[] GetQRCode(string plainText, int pixelsPerModule, byte[] darkColorRgba, byte[] lightColorRgba, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, bool drawQuietZones = true) { using (var qrGenerator = new QRCodeGenerator()) using (var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion)) using (var qrCode = new PngByteQRCode(qrCodeData)) return(qrCode.GetGraphic(pixelsPerModule, darkColorRgba, lightColorRgba, drawQuietZones)); }
/// <summary> /// Helper function to create an ArtQRCode graphic with a single function call /// </summary> /// <param name="plainText">Text/payload to be encoded inside the QR code</param> /// <param name="pixelsPerModule">Amount of px each dark/light module of the QR code shall take place in the final QR code image</param> /// <param name="darkColor">Color of the dark modules</param> /// <param name="lightColor">Color of the light modules</param> /// <param name="backgroundColor">Color of the background</param> /// <param name="eccLevel">The level of error correction data</param> /// <param name="forceUtf8">Shall the generator be forced to work in UTF-8 mode?</param> /// <param name="utf8BOM">Should the byte-order-mark be used?</param> /// <param name="eciMode">Which ECI mode shall be used?</param> /// <param name="requestedVersion">Set fixed QR code target version.</param> /// <param name="backgroundImage">A bitmap object that will be used as background picture</param> /// <param name="pixelSizeFactor">Value between 0.0 to 1.0 that defines how big the module dots are. The bigger the value, the less round the dots will be.</param> /// <param name="drawQuietZones">If true a white border is drawn around the whole QR Code</param> /// <param name="quietZoneRenderingStyle">Style of the quiet zones</param> /// <param name="backgroundImageStyle">Style of the background image (if set). Fill=spanning complete graphic; DataAreaOnly=Don't paint background into quietzone</param> /// <param name="finderPatternImage">Optional image that should be used instead of the default finder patterns</param> /// <returns>QRCode graphic as bitmap</returns> public static Bitmap GetQRCode(string plainText, int pixelsPerModule, Color darkColor, Color lightColor, Color backgroundColor, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, Bitmap backgroundImage = null, double pixelSizeFactor = 0.8, bool drawQuietZones = true, QuietZoneStyle quietZoneRenderingStyle = QuietZoneStyle.Flat, BackgroundImageStyle backgroundImageStyle = BackgroundImageStyle.DataAreaOnly, Bitmap finderPatternImage = null) { using (var qrGenerator = new QRCodeGenerator()) using (var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion)) using (var qrCode = new ArtQRCode(qrCodeData)) return(qrCode.GetGraphic(pixelsPerModule, darkColor, lightColor, backgroundColor, backgroundImage, pixelSizeFactor, drawQuietZones, quietZoneRenderingStyle, backgroundImageStyle, finderPatternImage)); }
public VersionInfoDetails(ECCLevel errorCorrectionLevel, Dictionary<EncodingMode, int> capacityDict) { this.ErrorCorrectionLevel = errorCorrectionLevel; this.CapacityDict = capacityDict; }
public ByteEncoder(int version, ECCLevel level) : base(version, level) { }
private static string GetFormatString(ECCLevel level, int maskVersion) { var generator = "10100110111"; var fStrMask = "101010000010010"; var fStr = (level == ECCLevel.L) ? "01" : (level == ECCLevel.M) ? "00" : (level == ECCLevel.Q) ? "11" : "10"; fStr += DecToBin(maskVersion, 3); var fStrEcc = fStr.PadRight(15, '0').TrimStart('0'); while (fStrEcc.Length > 10) { var sb = new StringBuilder(); generator = generator.PadRight(fStrEcc.Length, '0'); for (var i = 0; i < fStrEcc.Length; i++) sb.Append((Convert.ToInt32(fStrEcc[i]) ^ Convert.ToInt32(generator[i])).ToString()); fStrEcc = sb.ToString().TrimStart('0'); } fStrEcc = fStrEcc.PadLeft(10, '0'); fStr += fStrEcc; var sbMask = new StringBuilder(); for (var i = 0; i < fStr.Length; i++) sbMask.Append((Convert.ToInt32(fStr[i]) ^ Convert.ToInt32(fStrMask[i])).ToString()); return sbMask.ToString(); }
private int GetVersion(int length, EncodingMode encMode, ECCLevel eccLevel) { var version = this.capacityTable.Where( x => x.Details.Count( y => (y.ErrorCorrectionLevel == eccLevel && y.CapacityDict[encMode] >= Convert.ToInt32(length) ) ) > 0 ).Select(x => new { version = x.Version, capacity = x.Details.Single(y => y.ErrorCorrectionLevel == eccLevel) .CapacityDict[encMode] }).Min(x => x.version); return version; }
public QrCode CreateQrCode(string plainText, ECCLevel eccLevel, bool utf8Bom = false) { var encoding = GetEncodingFromPlaintext(plainText); var codedText = PlainTextToBinary(plainText, encoding, utf8Bom); var dataInputLength = GetDataLength(encoding, plainText, codedText); var version = GetVersion(dataInputLength, encoding, eccLevel); var modeIndicator = DecToBin((int)encoding, 4); var countIndicator = DecToBin(dataInputLength, GetCountIndicatorLength(version, encoding)); var bitString = modeIndicator + countIndicator; bitString += codedText; //Fill up data code word var eccInfo = _capacityEccTable.Where(x => x.Version == version && x.ErrorCorrectionLevel.Equals(eccLevel)).Single(); var dataLength = eccInfo.TotalDataCodewords * 8; var lengthDiff = dataLength - bitString.Length; if (lengthDiff > 0) { bitString += new string('0', Math.Min(lengthDiff, 4)); } if ((bitString.Length % 8) != 0) { bitString += new string('0', 8 - (bitString.Length % 8)); } while (bitString.Length < dataLength) { bitString += "1110110000010001"; } if (bitString.Length > dataLength) { bitString = bitString.Substring(0, dataLength); } //Calculate error correction words var codeWordWithEcc = new List <CodewordBlock>(); for (var i = 0; i < eccInfo.BlocksInGroup1; i++) { var bitStr = bitString.Substring(i * eccInfo.CodewordsInGroup1 * 8, eccInfo.CodewordsInGroup1 * 8); codeWordWithEcc.Add(new CodewordBlock { BitString = bitStr, BlockNumber = i + 1, GroupNumber = 1, CodeWords = BinaryStringToBitBlockList(bitStr), ECCWords = CalculateEccWords(bitStr, eccInfo) }); } bitString = bitString.Substring(eccInfo.BlocksInGroup1 * eccInfo.CodewordsInGroup1 * 8); for (var i = 0; i < eccInfo.BlocksInGroup2; i++) { var bitStr = bitString.Substring(i * eccInfo.CodewordsInGroup2 * 8, eccInfo.CodewordsInGroup2 * 8); codeWordWithEcc.Add(new CodewordBlock { BitString = bitStr, BlockNumber = i + 1, GroupNumber = 2, CodeWords = BinaryStringToBitBlockList(bitStr), ECCWords = CalculateEccWords(bitStr, eccInfo) }); } //Interleave code words var interleavedWordsSb = new StringBuilder(); for (var i = 0; i < Math.Max(eccInfo.CodewordsInGroup1, eccInfo.CodewordsInGroup2); i++) { foreach (var codeBlock in codeWordWithEcc) { if (codeBlock.CodeWords.Count > i) { interleavedWordsSb.Append(codeBlock.CodeWords[i]); } } } for (var i = 0; i < eccInfo.ECCPerBlock; i++) { foreach (var codeBlock in codeWordWithEcc) { if (codeBlock.ECCWords.Count > i) { interleavedWordsSb.Append(codeBlock.ECCWords[i]); } } } interleavedWordsSb.Append(new string('0', _remainderBits[version - 1])); var interleavedData = interleavedWordsSb.ToString(); //Place interleaved data on module matrix var qr = new QrCode(version); var blockedModules = new List <Rectangle>(); ModulePlacer.PlaceFinderPatterns(ref qr, ref blockedModules); ModulePlacer.ReserveSeperatorAreas(qr.ModuleMatrix.Count, ref blockedModules); ModulePlacer.PlaceAlignmentPatterns(ref qr, _alignmentPatternTable.Where(x => x.Version == version).Select(x => x.PatternPositions).First(), ref blockedModules); ModulePlacer.PlaceTimingPatterns(ref qr, ref blockedModules); ModulePlacer.PlaceDarkModule(ref qr, version, ref blockedModules); ModulePlacer.ReserveVersionAreas(qr.ModuleMatrix.Count, version, ref blockedModules); ModulePlacer.PlaceDataWords(ref qr, interleavedData, ref blockedModules); var maskVersion = ModulePlacer.MaskCode(ref qr, version, ref blockedModules); var formatStr = GetFormatString(eccLevel, maskVersion); ModulePlacer.PlaceFormat(ref qr, formatStr); if (version >= 7) { var versionString = GetVersionString(version); ModulePlacer.PlaceVersion(ref qr, versionString); } ModulePlacer.AddQuietZone(ref qr); return(qr); }
public ECCInfo(int version, ECCLevel errorCorrectionLevel, int totalDataCodewords, int eccPerBlock, int blocksInGroup1, int codewordsInGroup1, int blocksInGroup2, int codewordsInGroup2) { this.Version = version; this.ErrorCorrectionLevel = errorCorrectionLevel; this.TotalDataCodewords = totalDataCodewords; this.ECCPerBlock = eccPerBlock; this.BlocksInGroup1 = blocksInGroup1; this.CodewordsInGroup1 = codewordsInGroup1; this.BlocksInGroup2 = blocksInGroup2; this.CodewordsInGroup2 = codewordsInGroup2; }
private ErrorCorrectionLevel(ECCLevel level, uint eccBytesPerBlock, ECCGroupInfo[] _eccGroups) { this.ECCBytesPerBlock = eccBytesPerBlock; this.eccGroups = _eccGroups; this.Level = level; }
public static Bitmap GetQRCode(string plainText, int pixelsPerModule, Color darkColor, Color lightColor, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, Bitmap icon = null, int iconSizePercent = 15, int iconBorderWidth = 6, bool drawQuietZones = true) { using (var qrGenerator = new QRCodeGenerator()) using (var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion)) using (var qrCode = new QRCode(qrCodeData)) return(qrCode.GetGraphic(pixelsPerModule, darkColor, lightColor, icon, iconSizePercent, iconBorderWidth, drawQuietZones)); }
public QRCode CreateQrCode(string plainText, ECCLevel eccLevel) { return CreateQrCode (plainText, eccLevel, false); }
public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorString, string whiteSpaceString, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, string endOfLine = "\n") { using (var qrGenerator = new QRCodeGenerator()) using (var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion)) using (var qrCode = new AsciiQRCode(qrCodeData)) return(qrCode.GetGraphic(pixelsPerModule, darkColorString, whiteSpaceString, endOfLine)); }
public QrCodeActionResult(string qrCodeData, ECCLevel eccLevel = ECCLevel.M) { _qrCodeData = qrCodeData; _eccLevel = eccLevel; }
public AlphanumericEncoder(int version, ECCLevel level) : base(version, level) { }
public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, bool drawQuietZones = true, ImageType imgType = ImageType.Png) { using (var qrGenerator = new QRCodeGenerator()) using (var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion)) using (var qrCode = new Base64QRCode(qrCodeData)) return(qrCode.GetGraphic(pixelsPerModule, darkColorHtmlHex, lightColorHtmlHex, drawQuietZones, imgType)); }