Ejemplo n.º 1
0
        public static (QRCodeCreateResult result, Stream?stream, Exception?exception) Create(byte[] bytes, QrCode.Ecc?level = null)
        {
            level ??= QrCode.Ecc.Low;
            try
            {
                var qrCode     = QrCode.EncodeBinary(bytes, level); // Make the QR code symbol
                var foreground = IApplication.Instance.ActualTheme switch
                {
                    AppTheme.Dark => SKColors.White,
                    _ => SKColors.Black,
                };
                int scale = 10, border = 4;
                using SKBitmap bitmap = qrCode.ToBitmap(scale, border, foreground);
                SKData data = bitmap.Encode(SKEncodedImageFormat.Png, 90);

                return(QRCodeCreateResult.Success, data.AsStream(true), null);
            }
            catch (DataTooLongException e)
            {
                return(QRCodeCreateResult.DataTooLong, null, e);
            }
            catch (Exception e)
            {
                return(QRCodeCreateResult.Exception, null, e);
            }
        }
Ejemplo n.º 2
0
        private static void DoBinaryDemo()
        {
            // create binary data
            byte[] data =
            {
                0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00,
                0x01, 0x00, 0x80, 0x01, 0x00, 0xff, 0xff, 0xff,
                0x00, 0x00, 0x00, 0x21, 0xf9, 0x04, 0x01, 0x0a,
                0x00, 0x01, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00,
                0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x4c,
                0x01, 0x00, 0x3b
            };
            var qr = QrCode.EncodeBinary(data, QrCode.Ecc.Medium);

            SaveAsSvg(qr, "binary.svg");
        }