Exemple #1
0
 /// <summary>
 /// Helper function to create an ArtQRCode graphic with a single function call
 /// </summary>
 /// <param name="plainText">Text/payload to be encoded inside the QR code</param>
 /// <param name="pixelsPerModule">Amount of px each dark/light module of the QR code shall take place in the final QR code image</param>
 /// <param name="darkColor">Color of the dark modules</param>
 /// <param name="lightColor">Color of the light modules</param>
 /// <param name="backgroundColor">Color of the background</param>
 /// <param name="eccLevel">The level of error correction data</param>
 /// <param name="forceUtf8">Shall the generator be forced to work in UTF-8 mode?</param>
 /// <param name="utf8BOM">Should the byte-order-mark be used?</param>
 /// <param name="eciMode">Which ECI mode shall be used?</param>
 /// <param name="requestedVersion">Set fixed QR code target version.</param>
 /// <param name="backgroundImage">A bitmap object that will be used as background picture</param>
 /// <param name="pixelSizeFactor">Value between 0.0 to 1.0 that defines how big the module dots are. The bigger the value, the less round the dots will be.</param>
 /// <param name="drawQuietZones">If true a white border is drawn around the whole QR Code</param>
 /// <param name="quietZoneRenderingStyle">Style of the quiet zones</param>
 /// <param name="backgroundImageStyle">Style of the background image (if set). Fill=spanning complete graphic; DataAreaOnly=Don't paint background into quietzone</param>
 /// <param name="finderPatternImage">Optional image that should be used instead of the default finder patterns</param>
 /// <returns>QRCode graphic as bitmap</returns>
 public static Bitmap GetQRCode(string plainText, int pixelsPerModule, Color darkColor, Color lightColor, Color backgroundColor, ECCLevel eccLevel, bool forceUtf8 = false,
                                bool utf8BOM        = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, Bitmap backgroundImage = null, double pixelSizeFactor = 0.8,
                                bool drawQuietZones = true, QuietZoneStyle quietZoneRenderingStyle = QuietZoneStyle.Flat,
                                BackgroundImageStyle backgroundImageStyle = BackgroundImageStyle.DataAreaOnly, Bitmap finderPatternImage = null)
 {
     using (var qrGenerator = new QRCodeGenerator())
         using (var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion))
             using (var qrCode = new ArtQRCode(qrCodeData))
                 return(qrCode.GetGraphic(pixelsPerModule, darkColor, lightColor, backgroundColor, backgroundImage, pixelSizeFactor, drawQuietZones, quietZoneRenderingStyle, backgroundImageStyle, finderPatternImage));
 }
Exemple #2
0
 public static byte[] GetQRCode(string plainText, int pixelsPerModule, string darkColorHtmlHex,
                                string lightColorHtmlHex, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false,
                                EciMode eciMode = EciMode.Default, int requestedVersion = -1)
 {
     using (var qrGenerator = new QRCodeGenerator())
         using (
             var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode,
                                                       requestedVersion))
             using (var qrCode = new PdfByteQRCode(qrCodeData))
                 return(qrCode.GetGraphic(pixelsPerModule, darkColorHtmlHex, lightColorHtmlHex));
 }
Exemple #3
0
        private static QRCodeGenerator.EciMode MapEcimode(EciMode eciMode)
        {
            switch (eciMode)
            {
            case EciMode.Default:
                return(QRCodeGenerator.EciMode.Default);

            case EciMode.Iso8859_1:
                return(QRCodeGenerator.EciMode.Iso8859_1);

            case EciMode.Iso8859_2:
                return(QRCodeGenerator.EciMode.Iso8859_2);

            case EciMode.UTF8:
                return(QRCodeGenerator.EciMode.Utf8);

            default:
                throw new ArgumentOutOfRangeException(nameof(eciMode));
            }
        }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of a <see cref="QRCoderQRCodeProvider"/> with the specified
        /// <see cref="TwoFactorAuthNet.Providers.Qr.ErrorCorrectionLevel"/>, <see cref="BackgroundColor"/>,
        /// <see cref="ForegroundColor"/> and  <see cref="EciMode">EciMode</see>.
        /// </summary>
        /// <param name="errorCorrectionLevel">The <see cref="TwoFactorAuthNet.Providers.Qr.ErrorCorrectionLevel"/> to use when generating QR codes.</param>
        /// <param name="backgroundColor">The background color to be used for the QR code.</param>
        /// <param name="foregroundColor">The foreground color to be used for the QR code.</param>
        /// <param name="eciMode">The <see cref="EciMode"/> to be used for the QR code.</param>
        public QRCoderQRCodeProvider(
            ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.Low,
            Color?backgroundColor = null,
            Color?foregroundColor = null,
            EciMode eciMode       = EciMode.Default)
        {
            if (!Enum.IsDefined(typeof(ErrorCorrectionLevel), errorCorrectionLevel))
            {
                throw new ArgumentOutOfRangeException(nameof(errorCorrectionLevel));
            }
            ErrorCorrectionLevel = errorCorrectionLevel;

            BackgroundColor = backgroundColor ?? Color.White;
            ForegroundColor = foregroundColor ?? Color.Black;

            if (!Enum.IsDefined(typeof(EciMode), eciMode))
            {
                throw new ArgumentOutOfRangeException(nameof(eciMode));
            }
            EciMode = eciMode;
        }
Exemple #5
0
 public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorString, string whiteSpaceString, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, string endOfLine = "\n")
 {
     using (var qrGenerator = new QRCodeGenerator())
         using (var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion))
             using (var qrCode = new AsciiQRCode(qrCodeData))
                 return(qrCode.GetGraphic(pixelsPerModule, darkColorString, whiteSpaceString, endOfLine));
 }
Exemple #6
0
 public static Bitmap GetQRCode(string plainText, int pixelsPerModule, Color darkColor, Color lightColor, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, Bitmap icon = null, int iconSizePercent = 15, int iconBorderWidth = 6, bool drawQuietZones = true)
 {
     using (var qrGenerator = new QRCodeGenerator())
         using (var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion))
             using (var qrCode = new QRCode(qrCodeData))
                 return(qrCode.GetGraphic(pixelsPerModule, darkColor, lightColor, icon, iconSizePercent, iconBorderWidth, drawQuietZones));
 }
Exemple #7
0
 public static string GetQRCode(string plainText, int pointsPerModule, string darkColorHex, string lightColorHex, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, bool drawQuietZones = true, bool epsFormat = false)
 {
     using (var qrGenerator = new QRCodeGenerator())
         using (var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion))
             using (var qrCode = new PostscriptQRCode(qrCodeData))
                 return(qrCode.GetGraphic(pointsPerModule, darkColorHex, lightColorHex, drawQuietZones, epsFormat));
 }
Exemple #8
0
 public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorHex, string lightColorHex, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, bool drawQuietZones = true, SizingMode sizingMode = SizingMode.WidthHeightAttribute)
 {
     using (var qrGenerator = new QRCodeGenerator())
         using (var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion))
             using (var qrCode = new SvgQRCode(qrCodeData))
                 return(qrCode.GetGraphic(pixelsPerModule, darkColorHex, lightColorHex, drawQuietZones, sizingMode));
 }
Exemple #9
0
 public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, bool drawQuietZones = true, ImageType imgType = ImageType.Png)
 {
     using (var qrGenerator = new QRCodeGenerator())
         using (var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion))
             using (var qrCode = new Base64QRCode(qrCodeData))
                 return(qrCode.GetGraphic(pixelsPerModule, darkColorHtmlHex, lightColorHtmlHex, drawQuietZones, imgType));
 }
Exemple #10
0
 public static byte[] GetQRCode(string plainText, int pixelsPerModule, byte[] darkColorRgba, byte[] lightColorRgba, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, bool drawQuietZones = true)
 {
     using (var qrGenerator = new QRCodeGenerator())
         using (var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion))
             using (var qrCode = new PngByteQRCode(qrCodeData))
                 return(qrCode.GetGraphic(pixelsPerModule, darkColorRgba, lightColorRgba, drawQuietZones));
 }
 public static bool[,] GetQRArray(string plainText, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1)
 {
     using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
         using (QRCodeData qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion))
             using (QRCode qrCode = new QRCode(qrCodeData))
                 return(qrCode.GetArray());
 }
 public static Texture2D GetQRCode(string plainText, int pixelsPerModule, ECCLevel eccLevel = ECCLevel.Q, Color?darkColor = null, Color?lightColor = null, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, bool drawQuietZones = true)
 {
     using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
         using (QRCodeData qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion))
             using (QRCode qrCode = new QRCode(qrCodeData))
                 return(qrCode.GetGraphic(pixelsPerModule, darkColor ?? Color.black, lightColor ?? Color.white, drawQuietZones));
 }