public QRCodeData(byte[] rawData, bool isRawCompressed) { var bytes = new List <byte>(rawData); //Decompress if (isRawCompressed) { var input = new System.IO.MemoryStream(bytes.ToArray()); var output = new System.IO.MemoryStream(); using (var dstream = new System.IO.Compression.DeflateStream(input, System.IO.Compression.CompressionMode.Decompress)) { Stream4Methods.CopyTo(dstream, output); } bytes = new List <byte>(output.ToArray()); } //Set QR code version var sideLen = (int)bytes[0]; bytes.RemoveAt(0); this.Version = (sideLen - 21 - 8) / 4 + 1; //Unpack var modules = new Queue <bool>(); foreach (var b in bytes) { var bArr = new BitArray(new byte[] { b }); for (int i = 7; i >= 0; i--) { modules.Enqueue((b & (1 << i)) != 0); } } //Build module matrix this.ModuleMatrix = new List <BitArray>(); for (int y = 0; y < sideLen; y++) { this.ModuleMatrix.Add(new BitArray(sideLen)); for (int x = 0; x < sideLen; x++) { this.ModuleMatrix[y][x] = modules.Dequeue(); } } }
public QRCodeData(byte[] rawData, Compression compressMode) { var bytes = new List <byte>(rawData); //Decompress if (compressMode == Compression.Deflate) { using (var input = new MemoryStream(bytes.ToArray())) { using (var output = new MemoryStream()) { using (var dstream = new DeflateStream(input, CompressionMode.Decompress)) { Stream4Methods.CopyTo(dstream, output); } bytes = new List <byte>(output.ToArray()); } } } else if (compressMode == Compression.GZip) { using (var input = new MemoryStream(bytes.ToArray())) { using (var output = new MemoryStream()) { using (var dstream = new GZipStream(input, CompressionMode.Decompress)) { Stream4Methods.CopyTo(dstream, output); } bytes = new List <byte>(output.ToArray()); } } } if (bytes[0] != 0x51 || bytes[1] != 0x52 || bytes[2] != 0x52) { throw new Exception("Invalid raw data file. Filetype doesn't match \"QRR\"."); } //Set QR code version var sideLen = (int)bytes[4]; bytes.RemoveRange(0, 5); this.Version = (sideLen - 21 - 8) / 4 + 1; //Unpack var modules = new Queue <bool>(8 * bytes.Count); foreach (var b in bytes) { var bArr = new BitArray(new byte[] { b }); for (int i = 7; i >= 0; i--) { modules.Enqueue((b & (1 << i)) != 0); } } //Build module matrix this.ModuleMatrix = new List <BitArray>(sideLen); for (int y = 0; y < sideLen; y++) { this.ModuleMatrix.Add(new BitArray(sideLen)); for (int x = 0; x < sideLen; x++) { this.ModuleMatrix[y][x] = modules.Dequeue(); } } }