Esempio n. 1
0
        /// <summary>
        /// 创建混淆QR Code,第二个QR Code将藏在第一个里面。
        /// </summary>
        /// <param name="data1"></param>
        /// <param name="data2"></param>
        /// <returns></returns>
        public static (QRCode QRCode1, QRCode QRCode2, bool Swap) CreateObfuscatedQRCode(byte[] data1, byte[] data2)
        {
            for (int level = 0; level < 4; level++)
            {
                var eccLevel = (ECCLevel)level;
                var mode1    = DataEncoder.GuessMode(data1);
                while (true)
                {
                    var mode2 = DataEncoder.GuessMode(data2);
                    while (true)
                    {
                        var ver1 = DataEncoder.GuessVersion(data1.Length, eccLevel, mode1);
                        var ver2 = DataEncoder.GuessVersion(data2.Length, eccLevel, mode2);
                        var ver  = Math.Max(ver1, ver2);
                        for (; ver <= 40; ver++)
                        {
                            for (int mask1 = 0; mask1 < 8; mask1++)
                            {
                                var qr1 = QRCode.AnalysisOverlay(ver, mode1, data1, eccLevel, (MaskVersion)mask1);
                                for (int mask2 = 0; mask2 < 8; mask2++)
                                {
                                    var qr2      = QRCode.AnalysisOverlay(ver, mode2, data2, eccLevel, (MaskVersion)mask2);
                                    var foverlay = OverlayAnalyzer.IsOverlay(qr1.FormatBinary, qr2.FormatBinary);
                                    if (foverlay)
                                    {
                                        var overlay = OverlayAnalyzer.IsOverlay(qr1.AnalysisGroup, qr2.AnalysisGroup, qr1.MaxErrorAllowBytes + qr2.MaxErrorAllowBytes);
                                        if (overlay)
                                        {
                                            var(f1, f2) = OverlayAnalyzer.FormatOverlay(qr1.FormatBinary, qr2.FormatBinary);
                                            OverlayAnalyzer.Overlay(qr1.AnalysisGroup, qr2.AnalysisGroup, qr1.MaxErrorAllowBytes, qr2.MaxErrorAllowBytes);
                                            qr1.WriteFormatInformation(f1);
                                            qr2.WriteFormatInformation(f2);
                                            // if (!OverlayAnalyzer.IsOverlay(qr1.AnalysisGroup, qr2.AnalysisGroup, 0)) throw new InvalidOperationException();
                                            qr1.Flush();
                                            qr2.Flush();
                                            return(qr1, qr2, false);
                                        }
                                    }

                                    foverlay = OverlayAnalyzer.IsOverlay(qr2.FormatBinary, qr1.FormatBinary);
                                    if (foverlay)
                                    {
                                        var overlay = OverlayAnalyzer.IsOverlay(qr2.AnalysisGroup, qr1.AnalysisGroup, qr1.MaxErrorAllowBytes + qr2.MaxErrorAllowBytes);
                                        if (overlay)
                                        {
                                            var(f2, f1) = OverlayAnalyzer.FormatOverlay(qr2.FormatBinary, qr1.FormatBinary);
                                            OverlayAnalyzer.Overlay(qr2.AnalysisGroup, qr1.AnalysisGroup, qr2.MaxErrorAllowBytes, qr1.MaxErrorAllowBytes);
                                            qr1.WriteFormatInformation(f1);
                                            qr2.WriteFormatInformation(f2);
                                            // if (!OverlayAnalyzer.IsOverlay(qr2.AnalysisGroup, qr1.AnalysisGroup, 0)) throw new InvalidOperationException();
                                            qr1.Flush();
                                            qr2.Flush();
                                            return(qr2, qr1, true);
                                        }
                                    }
                                }
                            }
                        }
                        if (!NextMode(mode2, out mode2))
                        {
                            break;
                        }
                    }
                    if (!NextMode(mode1, out mode1))
                    {
                        break;
                    }
                }
            }
            return(default);
Esempio n. 2
0
 public QRSurface(QRCode qrCode, int cellWidth)
 {
     QRCode    = qrCode;
     CellWidth = cellWidth;
 }