Example #1
0
        public static void GenerateQrCode(string text, string file)
        {
            var qrSegment = QrSegment.MakeBytes(Encoding.UTF8.GetBytes(text));
            var qrCode    = QrCode.EncodeSegments(new List <QrSegment>()
            {
                qrSegment
            }, QrCode.Ecc.Low, 10, 40, 0, false);
            var qrCodePng = new QrCodePng(qrCode, 5, 5);

            File.WriteAllBytes(file, qrCodePng.GetBytes());
        }
Example #2
0
        // Creates QR Codes with manually specified segments for better compactness.
        private static void DoSegmentDemo()
        {
            QrCode           qr;
            List <QrSegment> segs;

            // Illustration "silver"
            var silver0 = "THE SQUARE ROOT OF 2 IS 1.";
            var silver1 = "41421356237309504880168872420969807856967187537694807317667973799";

            qr = QrCode.EncodeText(silver0 + silver1, Ecc.Low);
            WritePng(qr.ToImage(10, 3), "sqrt2-monolithic-QR.png");

            segs = new List <QrSegment>()
            {
                QrSegment.MakeAlphanumeric(silver0),
                QrSegment.MakeNumeric(silver1)
            };
            qr = QrCode.EncodeSegments(segs, Ecc.Low);
            WritePng(qr.ToImage(10, 3), "sqrt2-segmented-QR.png");

            // Illustration "golden"
            var golden0 = "Golden ratio φ = 1.";
            var golden1 = "6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911374";
            var golden2 = "......";

            qr = QrCode.EncodeText(golden0 + golden1 + golden2, Ecc.Low);
            WritePng(qr.ToImage(8, 5), "phi-monolithic-QR.png");

            segs = new List <QrSegment>()
            {
                QrSegment.MakeBytes(Encoding.UTF8.GetBytes(golden0)),
                QrSegment.MakeNumeric(golden1),
                QrSegment.MakeAlphanumeric(golden2)
            };
            qr = QrCode.EncodeSegments(segs, Ecc.Low);
            WritePng(qr.ToImage(8, 5), "phi-segmented-QR.png");

            // Illustration "Madoka": kanji, kana, Cyrillic, full-width Latin, Greek characters
            var madoka = "「魔法少女まどか☆マギカ」って、 ИАИ desu κα?";

            qr = QrCode.EncodeText(madoka, Ecc.Low);
            WritePng(qr.ToImage(9, 4), "madoka-utf8-QR.png");

            segs = new List <QrSegment>()
            {
                QrSegmentAdvanced.MakeKanji(madoka)
            };
            qr = QrCode.EncodeSegments(segs, Ecc.Low);
            WritePng(qr.ToImage(9, 4), "madoka-kanji-QR.png");
        }