void Utf8Encoding()
        {
            List <QrSegment> segments = QrSegment.MakeSegments(TextUtf8);

            Assert.Single(segments);
            QrSegment segment = segments[0];

            Assert.Equal(segment.EncodingMode, QrSegment.Mode.Byte);
            Assert.Equal(Encoding.UTF8.GetBytes(TextUtf8).Length, segment.NumChars);

            BitArray data = segment.GetData();

            Assert.Equal(BitLengthUtf8, data.Length);

            Assert.Equal(BitsUtf8, BitArrayToByteArray(data));
        }
        void AutoAlphanumericEncoding()
        {
            List <QrSegment> segments = QrSegment.MakeSegments(TextAlphanumeric);

            Assert.Single(segments);

            QrSegment segment = segments[0];

            Assert.Equal(segment.EncodingMode, QrSegment.Mode.Alphanumeric);
            Assert.Equal(TextAlphanumeric.Length, segment.NumChars);

            BitArray data = segment.GetData();

            Assert.Equal(BitLengthAlphanumeric, data.Length);

            Assert.Equal(BitsAlphanumeric, BitArrayToByteArray(data));
        }
Exemple #3
0
        // Creates QR codes with the same size and contents but different mask patterns.
        private static void DoMaskDemo()
        {
            // Project Nayuki URL
            var segs = QrSegment.MakeSegments("https://www.nayuki.io/");
            var qr   = QrCode.EncodeSegments(segs, QrCode.Ecc.High);

            SaveAsPng(qr, "project-nayuki-automask-QR.png", 8, 6);
            qr = QrCode.EncodeSegments(segs, QrCode.Ecc.High, QrCode.MinVersion, QrCode.MaxVersion, 3);          // Force mask 3
            SaveAsPng(qr, "project-nayuki-mask3-QR.png", 8, 6);

            // Chinese text as UTF-8
            segs = QrSegment.MakeSegments("維基百科(Wikipedia,聆聽i/ˌwɪkᵻˈpiːdi.ə/)是一個自由內容、公開編輯且多語言的網路百科全書協作計畫");
            qr   = QrCode.EncodeSegments(segs, QrCode.Ecc.Medium, QrCode.MinVersion, QrCode.MaxVersion, 0);        // Force mask 0
            SaveAsPng(qr, "unicode-mask0-QR.png", 10, 3);
            qr = QrCode.EncodeSegments(segs, QrCode.Ecc.Medium, QrCode.MinVersion, QrCode.MaxVersion, 1);          // Force mask 1
            SaveAsPng(qr, "unicode-mask1-QR.png", 10, 3);
            qr = QrCode.EncodeSegments(segs, QrCode.Ecc.Medium, QrCode.MinVersion, QrCode.MaxVersion, 5);          // Force mask 5
            SaveAsPng(qr, "unicode-mask5-QR.png", 10, 3);
            qr = QrCode.EncodeSegments(segs, QrCode.Ecc.Medium, QrCode.MinVersion, QrCode.MaxVersion, 7);          // Force mask 7
            SaveAsPng(qr, "unicode-mask7-QR.png", 10, 3);
        }
Exemple #4
0
        // Creates QR Codes with the same size and contents but different mask patterns.
        private static void DoMaskDemo()
        {
            QrCode           qr;
            List <QrSegment> segs;

            // Project Nayuki URL
            segs = QrSegment.MakeSegments("https://www.nayuki.io/");
            qr   = QrCode.EncodeSegments(segs, Ecc.High, QrCode.MIN_VERSION, QrCode.MAX_VERSION, -1, true); // Automatic mask
            WritePng(qr.ToImage(8, 6), "project-nayuki-automask-QR.png");
            qr = QrCode.EncodeSegments(segs, Ecc.High, QrCode.MIN_VERSION, QrCode.MAX_VERSION, 3, true);    // Force mask 3
            WritePng(qr.ToImage(8, 6), "project-nayuki-mask3-QR.png");

            // Chinese text as UTF-8
            segs = QrSegment.MakeSegments("維基百科(Wikipedia,聆聽i/ˌwɪkᵻˈpiːdi.ə/)是一個自由內容、公開編輯且多語言的網路百科全書協作計畫");
            qr   = QrCode.EncodeSegments(segs, Ecc.Medium, QrCode.MIN_VERSION, QrCode.MAX_VERSION, 0, true); // Force mask 0
            WritePng(qr.ToImage(10, 3), "unicode-mask0-QR.png");
            qr = QrCode.EncodeSegments(segs, Ecc.Medium, QrCode.MIN_VERSION, QrCode.MAX_VERSION, 1, true);   // Force mask 1
            WritePng(qr.ToImage(10, 3), "unicode-mask1-QR.png");
            qr = QrCode.EncodeSegments(segs, Ecc.Medium, QrCode.MIN_VERSION, QrCode.MAX_VERSION, 5, true);   // Force mask 5
            WritePng(qr.ToImage(10, 3), "unicode-mask5-QR.png");
            qr = QrCode.EncodeSegments(segs, Ecc.Medium, QrCode.MIN_VERSION, QrCode.MAX_VERSION, 7, true);   // Force mask 7
            WritePng(qr.ToImage(10, 3), "unicode-mask7-QR.png");
        }
        void EmptyTest()
        {
            List <QrSegment> segments = QrSegment.MakeSegments("");

            Assert.Empty(segments);
        }