public string GetQrCodeAsAscii() { using (var qrGenerator = new QRCodeGenerator()) { var qrCodeData = qrGenerator.CreateQrCode(Code, QRCodeGenerator.ECCLevel.Q); using (var qrCode = new AsciiQRCode(qrCodeData)) { return(qrCode.GetGraphic(1)); } } }
public void can_render_ascii_qrcode() { var targetCode = " \n \n \n \n ██████████████ ██ ██ ██████████████ \n ██ ██ ██ ████ ██ ██ \n ██ ██████ ██ ██ ██ ██ ██ ██████ ██ \n ██ ██████ ██ ██ ██ ██████ ██ \n ██ ██████ ██ ██ ██ ██████ ██ \n ██ ██ ████████ ██ ██ \n ██████████████ ██ ██ ██ ██████████████ \n ██ ████ \n ██████████ ████ ████████ ██ ████ \n ████ ██ ██ ████ ████████ ██ \n ██ ██ ██████████ ██ ██ ██ ████ \n ██ ██ ████ ████ ████ \n ████████ ██████ ████ ██ ██ \n ████████ \n ██████████████ ████ ████ ██ ████ ████ \n ██ ██ ████████ \n ██ ██████ ██ ██ ██ ██ ██ ██ ██ \n ██ ██████ ██ ██████ ██ ██ \n ██ ██████ ██ ██ ██ ██ ██ ████ ████ \n ██ ██ ████ ████ ██ ██ \n ██████████████ ██████ ██ ██████ \n \n \n \n "; //Create QR code var gen = new QRCodeGenerator(); var data = gen.CreateQrCode("A05", QRCodeGenerator.ECCLevel.Q); var asciiCode = new AsciiQRCode(data).GetGraphic(1); asciiCode.ShouldBe(targetCode); }
static void ConsoleWriteQRCode(string textToEncode) { var generator = new QRCodeGenerator(); var encodedText = generator.CreateQrCode(textToEncode, QRCodeGenerator.ECCLevel.Q); using (var qrCode = new AsciiQRCode(encodedText)) { var qrCodeAsAsciiArt = qrCode.GetGraphic(1); Console.WriteLine(qrCodeAsAsciiArt); } }
static void perform(string s, int i) { QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(s, QRCodeGenerator.ECCLevel.M, //requestedVersion:8, forcedpattern: 1); AsciiQRCode qra = new AsciiQRCode(qrCodeData); //foreach (string s in qra.GetLineByLineGraphic(1)) //{ // Console.WriteLine(s); //} //foreach (string s in qra.GetLineByLineSource()) //{ // Console.WriteLine(s); //} QRCode qrc = new QRCode(qrCodeData); //var b = qrc.GetGraphic(10, new ColorProviders.ColorProviderDebug()); //b.Save("out" + v + ".png"); //return; Image glowka = Bitmap.FromFile("glowka.png"); var c = qrc.GetGraphic(12, new ColorProviders.ColorProviderBW()); Bitmap newImage = new Bitmap(c.Width, c.Height + 40, c.PixelFormat); //Graphics g = Graphics.FromImage(c); Graphics g = Graphics.FromImage(newImage); g.FillRectangle(Brushes.White, 0, 0, newImage.Width, newImage.Height); g.DrawImage(c, 0, 0); //g.DrawImage(glowka, newImage.Width/2-glowka.Width/2, glowka.Width ); RectangleF rectf = new RectangleF(15, c.Height - 10, c.Width, 100); g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.DrawString(s, new Font("Consolas", 20, FontStyle.Bold), Brushes.Black, rectf); g.Flush(); string fname = String.Format("out_{0:000}.png", i); newImage.Save(fname); }
private static void TestTOTP() { Console.WriteLine("======================== TOTP Test ========================"); Console.WriteLine("Creating new user with data:"); var user = new Models.FakeUser("John", "hunter2", ""); Console.WriteLine("Username: "******"Password: "******"ezauth_totp_test"); user.TOTPSecret = totp.SecretKey; Console.WriteLine("TOTPSecret: " + user.TOTPSecret); Console.WriteLine("\nPlease scan this code into your authenticator: \n"); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(totp.GetOTPURI(), QRCodeGenerator.ECCLevel.M); AsciiQRCode qrCode = new AsciiQRCode(qrCodeData); string qrCodeAsAsciiArt = qrCode.GetGraphic(1, " ", "██"); Console.WriteLine(qrCodeAsAsciiArt); Console.WriteLine("\nYou now may enter codes from your authenticator to test"); Console.WriteLine("Enter 'q' to stop."); string input; Console.Write("> "); while ((input = Console.ReadLine()) != "q") { var res = totp.Validate(user.username, input); if (res == AuthResult.VALIDATED) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Valid code!"); Console.ForegroundColor = ConsoleColor.White; } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Invalid code"); Console.ForegroundColor = ConsoleColor.White; } Console.Write("> "); } }
static void Main(string[] args) { Console.WriteLine("Hello World!"); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode("https://news.ycombinator.com/item?id=111111", QRCodeGenerator.ECCLevel.Q); using (var qrCode = new AsciiQRCode(qrCodeData)) { string qrCodeAsAsciiArt = qrCode.GetGraphic(1); Console.WriteLine(qrCodeAsAsciiArt); } Console.WriteLine("Generated QRCode!"); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", QRCodeGenerator.ECCLevel.Q); using (var qrCode = new AsciiQRCode(qrCodeData)) { string qrCodeAsAsciiArt = qrCode.GetGraphic(1); Console.WriteLine(qrCodeAsAsciiArt); } Console.WriteLine("Generated QRCode!"); }
public async Task QRCodeTerminalAsAscii(string qrCode) { string qrcodeImageUrl = GetWechatGithubQrCode(qrCode); Url generator = new Url(qrcodeImageUrl); string payload = generator.ToString(); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.L); AsciiQRCode qrCodeAsi = new AsciiQRCode(qrCodeData); string qrCodeAsAsciiArt = qrCodeAsi.GetGraphic(1); Console.WriteLine(qrCodeAsAsciiArt); await Message.Say("Hello this is come from plugin "); }
public Task <Unit> Handle(GenerateNewQrCodeCommand request, CancellationToken cancellationToken) { // clear the console for optimum display _output.Clear(); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode( plainText: request.Contents, eccLevel: 0 ); AsciiQRCode qrCode = new AsciiQRCode(qrCodeData); string render = qrCode.GetGraphic(1); _output.Write(render); return(Task.FromResult(Unit.Value)); }
static void Main() { string localIP = ""; var hostName = Dns.GetHostName(); foreach (var item in Dns.GetHostEntry(hostName).AddressList) { if (item.AddressFamily == AddressFamily.InterNetwork) { localIP = item.ToString(); } } //TcpListener finds a free port for us, so there is no risk of conflicting with another application TcpListener server = new TcpListener(IPAddress.Loopback, 0); server.Start(); string localPort = ((IPEndPoint)server.LocalEndpoint).Port.ToString(); server.Stop(); Console.WriteLine("Host:\t\t" + hostName); Console.WriteLine("IP Address:\t" + localIP); Console.WriteLine("Port:\t\t" + localPort); Console.WriteLine(); var generator = new QRCodeGenerator(); var data = generator.CreateQrCode(localIP + ":" + localPort, QRCodeGenerator.ECCLevel.Q); var code = new AsciiQRCode(data); var image = code.GetGraphic(1); Console.WriteLine(image); Terminal.Build(); WebHost.CreateDefaultBuilder() .UseUrls($"http://{localIP}:{localPort}") .UseSetting(WebHostDefaults.SuppressStatusMessagesKey, "true") .ConfigureServices(services => services.AddMvc()) .ConfigureLogging(log => log.ClearProviders()) .Configure(app => { app.UseMvc(); app.UseCors(c => c.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()); }) .Build() .Run(); }
/// <summary> /// Creates the QR code. /// </summary> /// <param name="qrString">The qrString.</param> private Image <Rgba32> CreateQrCode(string qrString) { // how much space is available on canvas for the qr code const int pixelSpace = 316; // initialize qr generator var qrGenerator = new QRCodeGenerator(); var qrData = qrGenerator.CreateQrCode(qrString, QRCodeGenerator.ECCLevel.L); // get the "ASCII bitmap" var bitmapStrings = new AsciiQRCode(qrData).GetLineByLineGraphic(1, "1", "0"); if ((bitmapStrings == null) || (bitmapStrings.Length < 1)) { throw new InvalidDataException("QRCoder produced invalid QR string."); } // remove the side padding (if any) var fromIndex = bitmapStrings[0].IndexOf('1'); var length = bitmapStrings[0].LastIndexOf('1') + 1 - fromIndex; bitmapStrings = bitmapStrings .Select(line => line.Substring(fromIndex, length)) .ToArray(); // how many real pixels is one "qr pixel" var pixelSize = pixelSpace / bitmapStrings[0].Length; // create image of proper size var qrCodeImage = new Image <Rgba32>(pixelSize * bitmapStrings[0].Length, pixelSize * bitmapStrings.Length); // drwa the qr code for (var j = 0; j < bitmapStrings.Length; j++) { var row = bitmapStrings[j]; for (var i = 0; i < row.Length; i++) { var qrPixel = (Rgba32)((row[i] == '0') ? Color.White : Color.Black); this.DrawQrPixel(qrCodeImage, pixelSize, i, j, qrPixel); } } return(qrCodeImage); }
public void QRCodeTerminalAsAscii() { WechahtyEvent.Subscribe <EventScanPayload>(async(eventData) => { if (eventData.Status == ScanStatus.Waiting || eventData.Status == ScanStatus.Timeout) { await Task.Run(() => { string qrcodeImageUrl = GetWechatGithubQrCode(eventData.Qrcode); Url generator = new Url(qrcodeImageUrl); string payload = generator.ToString(); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.L); AsciiQRCode qrCodeAsi = new AsciiQRCode(qrCodeData); string qrCodeAsAsciiArt = qrCodeAsi.GetGraphic(1); Console.WriteLine(qrCodeAsAsciiArt); }); } }); }
public string GetQrCodeAsAscii() { var qrCode = new AsciiQRCode(_qrCodeData); return(qrCode.GetGraphic(1)); }
private static void GenerateQRCode(string payloadString, QRCodeGenerator.ECCLevel eccLevel, string outputFileName, SupportedImageFormat imgFormat, int pixelsPerModule, string foreground, string background) { using (var generator = new QRCodeGenerator()) { using (var data = generator.CreateQrCode(payloadString, eccLevel)) { switch (imgFormat) { case SupportedImageFormat.Png: case SupportedImageFormat.Jpg: case SupportedImageFormat.Gif: case SupportedImageFormat.Bmp: case SupportedImageFormat.Tiff: using (var code = new QRCode(data)) { using (var bitmap = code.GetGraphic(pixelsPerModule, foreground, background, true)) { var actualFormat = new OptionSetter().GetImageFormat(imgFormat.ToString()); bitmap.Save(outputFileName, actualFormat); } } break; case SupportedImageFormat.Svg: using (var code = new SvgQRCode(data)) { var test = code.GetGraphic(pixelsPerModule, foreground, background, true); using (var f = File.CreateText(outputFileName)) { f.Write(test); f.Flush(); } } break; case SupportedImageFormat.Xaml: using (var code = new XamlQRCode(data)) { var test = XamlWriter.Save(code.GetGraphic(pixelsPerModule, foreground, background, true)); using (var f = File.CreateText(outputFileName)) { f.Write(test); f.Flush(); } } break; case SupportedImageFormat.Ps: case SupportedImageFormat.Eps: using (var code = new PostscriptQRCode(data)) { var test = code.GetGraphic(pixelsPerModule, foreground, background, true, imgFormat == SupportedImageFormat.Eps); using (var f = File.CreateText(outputFileName)) { f.Write(test); f.Flush(); } } break; case SupportedImageFormat.Ascii: using (var code = new AsciiQRCode(data)) { var test = code.GetGraphic(1); var bytes = Encoding.GetEncoding(866).GetBytes(test); File.WriteAllBytes(outputFileName, bytes); } break; default: throw new ArgumentOutOfRangeException(nameof(imgFormat), imgFormat, null); } } } }