public Bitmap stringToBitmap(string contents) { qRCodeData = qRCodeGenerator.CreateQrCode(contents, QRCodeGenerator.ECCLevel.H); bitmapByteQRCode = new BitmapByteQRCode(qRCodeData); return(BitmapFactory.DecodeByteArray(bitmapByteQRCode.GetGraphic(20), 0, bitmapByteQRCode.GetGraphic(20).Length)); }
public Bitmap stringToBitmap(string name, string number) { string temp = "{\"name\":\"" + name + "\",\"number\":\"" + number + "\"}"; qRCodeData = qRCodeGenerator.CreateQrCode(temp, QRCodeGenerator.ECCLevel.H); bitmapByteQRCode = new BitmapByteQRCode(qRCodeData); return(BitmapFactory.DecodeByteArray(bitmapByteQRCode.GetGraphic(20), 0, bitmapByteQRCode.GetGraphic(20).Length)); }
private async void button_Click(object sender, RoutedEventArgs e) { if (comboBoxECC.SelectedItem != null) { string level = comboBoxECC.SelectedItem.ToString(); QRCodeGenerator.ECCLevel eccLevel = (QRCodeGenerator.ECCLevel)(level == "L" ? 0 : level == "M" ? 1 : level == "Q" ? 2 : 3); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", eccLevel); BitmapByteQRCode qrCode = new BitmapByteQRCode(qrCodeData); byte[] qrCodeImage = qrCode.GetGraphic(20); using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream()) { using (DataWriter writer = new DataWriter(stream.GetOutputStreamAt(0))) { writer.WriteBytes(qrCodeImage); await writer.StoreAsync(); } var image = new BitmapImage(); await image.SetSourceAsync(stream); imageViewer.Source = image; } } }
public async Task <byte[]> CreateQRAsync(string text) { //if (comboBoxECC.SelectedItem != null) { //Create generator string level = "Q"; QRCodeGenerator.ECCLevel eccLevel = (QRCodeGenerator.ECCLevel)(level == "L" ? 0 : level == "M" ? 1 : level == "Q" ? 2 : 3); //Create raw qr code data QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(text, eccLevel); //Create byte/raw bitmap qr code BitmapByteQRCode qrCodeBmp = new BitmapByteQRCode(qrCodeData); byte[] qrCodeImageBmp = qrCodeBmp.GetGraphic(20, new byte[] { 0, 0, 0 }, new byte[] { 255, 255, 255 }); ////Create byte/raw png qr code //PngByteQRCode qrCodePng = new PngByteQRCode(qrCodeData); //byte[] qrCodeImagePng = qrCodePng.GetGraphic(20, new byte[] { 144, 201, 111 }, new byte[] { 118, 126, 152 }); //QRImage.Source = LoadImage(qrCodeImageBmp); return(qrCodeImageBmp); } }
public static async Task <WriteableBitmap> GenerateQRCodeAsync(string content, MyColor darkColor, MyColor lightColor = null) { if (darkColor == null) { throw new ArgumentNullException(nameof(darkColor)); } var payload = new PayloadGenerator.Url(content ?? string.Empty); byte[] GetRGB(MyColor c) => new[] { c.R, c.G, c.B }; using (var generator = new QRCodeGenerator()) using (var data = generator.CreateQrCode(payload.ToString(), ECCLevel.Q)) using (var code = new BitmapByteQRCode(data)) using (var stream = new InMemoryRandomAccessStream()) using (var writer = new DataWriter(stream.GetOutputStreamAt(0))) { var darkRGB = GetRGB(darkColor); var lightRGB = lightColor == null ? new[] { Byte.MaxValue, Byte.MaxValue, Byte.MaxValue, } : GetRGB(lightColor); writer.WriteBytes(code.GetGraphic(20, darkRGB, lightRGB)); await writer.StoreAsync(); var bitmap = new WriteableBitmap(1024, 1024); await bitmap.SetSourceAsync(stream); return(bitmap); } }
private PdfPTable Barcode() { PdfPTable pdf = new PdfPTable(3); var content = exporterDeclaration.Select(i => i.CciNo).FirstOrDefault(); QRCodeGenerator qr = new QRCodeGenerator(); QRCodeData codeData = qr.CreateQrCode(content, QRCodeGenerator.ECCLevel.Q); BitmapByteQRCode qrCode = new BitmapByteQRCode(codeData); byte[] qrCodeAsBitmapByteArr = qrCode.GetGraphic(3); Image image = Image.GetInstance(qrCodeAsBitmapByteArr); pdfPCell = new PdfPCell(image); pdfPCell.Colspan = 3; pdfPCell.HorizontalAlignment = Element.ALIGN_RIGHT; pdfPCell.VerticalAlignment = Element.ALIGN_MIDDLE; pdfPCell.Border = 0; pdfPCell.ExtraParagraphSpace = 0; pdfTable.AddCell(pdfPCell); pdf.CompleteRow(); return(pdf); }
private async Task CreateQR(int index) { this.tb2.Text = "PDU-ID: " + index; var url = string.Format(UrlTextBox.Text, index); var qrGenerator = new QRCodeGenerator(); var payload = new PayloadGenerator.Url(url); var dark = new[] { byte.MinValue, byte.MinValue, byte.MinValue }; var light = new[] { byte.MaxValue, byte.MaxValue, byte.MaxValue }; var qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q); var qrCode = new BitmapByteQRCode(qrCodeData); var qrCodeImage = qrCode.GetGraphic(20, dark, light); using (var stream = new InMemoryRandomAccessStream()) { using (var writer = new DataWriter(stream.GetOutputStreamAt(0))) { writer.WriteBytes(qrCodeImage); await writer.StoreAsync(); } var image = new BitmapImage(); await image.SetSourceAsync(stream); QRImage.Source = image; } }
public void renderCode() { QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode("https://remote.mimic.lol/" + hubCode, QRCodeGenerator.ECCLevel.Q); BitmapByteQRCode qrCode = new BitmapByteQRCode(qrCodeData); byte[] qrCodeAsBitmapByteArr = qrCode.GetGraphic(20); // ConnectionQR.Source = qrCode.GetGraphic(20); // ConnectionQR.Visibility = Visibility.Visible; // CodeLabel.Content = Persistence.GetHubCode(); // CodeLabel.Visibility = Visibility.Visible; // ConnectionSteps.Visibility = Visibility.Visible; // NoCodeText.Visibility = Visibility.Hidden; NSData imageData = NSData.FromArray(qrCodeAsBitmapByteArr); QRCodeImage.Image = new NSImage(imageData); codeLabel.StringValue = hubCode; }
public async Task <ActionResult> Generate() { string input = null; // If not data came in, then return if (this.Request.Body == null) { return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel("Request content is null", HttpStatusCode.Conflict))); } // Read the input claims from the request body using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8)) { input = await reader.ReadToEndAsync(); } // Check input content value if (string.IsNullOrEmpty(input)) { return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel("Request content is empty", HttpStatusCode.Conflict))); } // Convert the input string into InputClaimsModel object InputClaimsModel inputClaims = InputClaimsModel.Parse(input); if (inputClaims == null) { return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel("Can not deserialize input claims", HttpStatusCode.Conflict))); } try { // Define the URL for the QR code. When user scan this URL, it opens one of the // authentication apps running on the mobile device byte[] secretKey = KeyGeneration.GenerateRandomKey(20); string TOTPUrl = KeyUrl.GetTotpUrl(secretKey, $"{AppSettings.TOTPAccountPrefix}:{inputClaims.userName}", AppSettings.TOTPTimestep); TOTPUrl = $"{TOTPUrl}&issuer={AppSettings.TOTPIssuer.Replace(" ", "%20")}"; // Generate QR code for the above URL var qrCodeGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrCodeGenerator.CreateQrCode(TOTPUrl, QRCodeGenerator.ECCLevel.L); BitmapByteQRCode qrCode = new BitmapByteQRCode(qrCodeData); byte[] qrCodeBitmap = qrCode.GetGraphic(4); B2CResponseModel output = new B2CResponseModel(string.Empty, HttpStatusCode.OK) { qrCodeBitmap = Convert.ToBase64String(qrCodeBitmap), secretKey = this.EncryptAndBase64(Convert.ToBase64String(secretKey)) }; return(Ok(output)); } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel($"General error (REST API): {ex.Message}", HttpStatusCode.Conflict))); } }
public byte[] Create(string data, QRCodeLevel level, int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex) { QRCodeGenerator.ECCLevel lv = (QRCodeGenerator.ECCLevel)((int)level); var qrcodeData = CreateQrCode(data, lv); BitmapByteQRCode code = new BitmapByteQRCode(qrcodeData); return(code.GetGraphic(pixelsPerModule, darkColorHtmlHex: darkColorHtmlHex, lightColorHtmlHex: lightColorHtmlHex)); }
public byte[] Create(string data, QRCodeLevel level = QRCodeLevel.Q, int pixelsPerModule = 20) { QRCodeGenerator.ECCLevel lv = (QRCodeGenerator.ECCLevel)((int)level); var qrcodeData = CreateQrCode(data, lv); BitmapByteQRCode code = new BitmapByteQRCode(qrcodeData); return(code.GetGraphic(pixelsPerModule)); }
/// <summary> /// 绘制二维码(有边距) /// </summary> /// <param name="content"></param> /// <returns>Bitmap</returns> public byte[] RenderBitmapBytes(string content) { QRCodeGenerator generator = new QRCodeGenerator(); QRCodeData data = generator.CreateQrCode(content, _eccLevel); var qrCode = new BitmapByteQRCode(data); return(qrCode.GetGraphic(Config.Size, Config.DarkColor, Config.LightColor)); }
private byte[] GetQrCodeBytes(string url) { var payload = new PayloadGenerator.Url(url); var qrCode = new BitmapByteQRCode(_qrGenerator.CreateQrCode(payload)); var bytes = qrCode.GetGraphic(3); return(bytes); }
/// <summary> /// 创建二维码 /// </summary> /// <param name="content">内容</param> public byte[] CreateQrCode(string content) { QRCodeGenerator generator = new QRCodeGenerator(); QRCodeData data = generator.CreateQrCode(content, level); BitmapByteQRCode qrCode = new BitmapByteQRCode(data); return(qrCode.GetGraphic(size)); }
/// <summary> /// 创建二维码 /// </summary> /// <param name="content">内容</param> public byte[] CreateQrCode(string content) { var generator = new QRCodeGenerator(); var data = generator.CreateQrCode(content, _level); var qrCode = new BitmapByteQRCode(data); return(qrCode.GetGraphic(_size)); }
public static byte[] GenerateQRCode(string input) { QRCoder.QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(input, QRCoder.QRCodeGenerator.ECCLevel.Q); BitmapByteQRCode qrCode = new BitmapByteQRCode(qrCodeData); return(qrCode.GetGraphic(10)); }
public IActionResult GetQrCode([FromRoute] string sessionName) { var gen = new QRCodeGenerator(); var data = gen.CreateQrCode($"{_clientConfiguration.Url}/#/join/{_sanitizerService.LettersAndDigits(sessionName)}", QRCodeGenerator.ECCLevel.Q); var qrcode = new BitmapByteQRCode(data); var byteArray = qrcode.GetGraphic(20); return(File(byteArray, "image/bmp")); }
public MemoryStream GenerateQRCode(string code) { QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q); BitmapByteQRCode bitmapByte = new BitmapByteQRCode(qrCodeData); return(new MemoryStream(bitmapByte.GetGraphic(20))); }
public FileContentResult MakeQrCode(string data) { var qrGenerator = new QRCodeGenerator(); var qrCodeData = qrGenerator.CreateQrCode(data, QRCodeGenerator.ECCLevel.Q); var qrCode = new BitmapByteQRCode(qrCodeData); var qrCodeImage = qrCode.GetGraphic(20); return(File(qrCodeImage, "image/gif")); }
public async Task <IActionResult> GenerateAsync( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "totp/generate")] HttpRequest request, ILogger log) { log.LogInformation("Start QrCode Generate Function."); if (request.Body is null) { return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel("Request content is null", HttpStatusCode.Conflict))); } var input = await new StreamReader(request.Body, Encoding.UTF8).ReadToEndAsync(); if (string.IsNullOrEmpty(input)) { return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel("Request content is empty", HttpStatusCode.Conflict))); } var inputClaims = InputClaimsModel.Parse(input); if (inputClaims == null) { return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel("Can not deserialize input claims", HttpStatusCode.Conflict))); } try { var secretKey = KeyGeneration.GenerateRandomKey(20); var TOTPUrl = GetTotpUrl(secretKey , inputClaims.UserName , _options.TOTPIssuer , _options.TOTPTimestep , _options.TOTPAccountPrefix); // Generate QR code for the above URL var qrCodeGenerator = new QRCodeGenerator(); var qrCodeData = qrCodeGenerator.CreateQrCode(TOTPUrl, QRCodeGenerator.ECCLevel.L); var qrCode = new BitmapByteQRCode(qrCodeData); var qrCodeBitmap = qrCode.GetGraphic(4); var output = new B2CResponseModel(string.Empty, HttpStatusCode.OK) { QrCodeBitmap = Convert.ToBase64String(qrCodeBitmap), SecretKey = EncryptAndBase64(Convert.ToBase64String(secretKey)) }; return(Ok(output)); } catch (Exception e) { return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseModel($"General error (REST API): {e.Message}", HttpStatusCode.Conflict))); } }
public QrCodeDialog(string title, string description, QRCodeData qrData) { this.title = title; this.Description = description; this.InitializeComponent(); dialogBrush = new ClientDialogBrush(); BitmapByteQRCode qrCode = new BitmapByteQRCode(qrData); qrCodeImageBmp = qrCode.GetGraphic(20); LoadQrImage(); }
public void Init() { Address = FindParent <WalletLayout>().Address; labelAddress.Text = Address; var qrGenerator = new QRCodeGenerator(); var qrCodeData = qrGenerator.CreateQrCode(Address, QRCodeGenerator.ECCLevel.Q); var qrCode = new BitmapByteQRCode(qrCodeData); _QrCodeImage = qrCode.GetGraphic(20); }
public void Handle(string input) { var qrGenerator = new QRCodeGenerator(); var qrCodeData = qrGenerator.CreateQrCode(input, QRCodeGenerator.ECCLevel.Q); var qrCode = new BitmapByteQRCode(qrCodeData); var qrCodeAsBitmapByteArray = qrCode.GetGraphic(20); using (Stream outStream = Console.OpenStandardOutput()) { outStream.Write(qrCodeAsBitmapByteArray, 0, qrCodeAsBitmapByteArray.Length); } }
private string QRCodegenerator() { QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qRCodeData = qrGenerator.CreateQrCode("derob", QRCodeGenerator.ECCLevel.M); //create byte/raw bitmap qr code BitmapByteQRCode qrCodeBmp = new BitmapByteQRCode(qRCodeData); byte[] qrCodeImageBmp = qrCodeBmp.GetGraphic(4); var h = Convert.ToBase64String(qrCodeImageBmp); return(h); }
private string QRCodegenerator(string ticketbarcode) { QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qRCodeData = qrGenerator.CreateQrCode(ticketbarcode, QRCodeGenerator.ECCLevel.M); //create byte/raw bitmap qr code BitmapByteQRCode qrCodeBmp = new BitmapByteQRCode(qRCodeData); byte[] qrCodeImageBmp = qrCodeBmp.GetGraphic(4); //var h = Convert.ToBase64String(qrCodeImageBmp); var qrurl = String.Format("data:image/png;base64,{0}", Convert.ToBase64String(qrCodeImageBmp)); return(qrurl); }
public (byte[] content, string mimeType) GetSiteUrlQrCode() { string siteUrl = configuration.GetServerUrls().First(); QRCodeGenerator qrGenerator = new QRCodeGenerator(); PayloadGenerator.Bookmark bookmark = new PayloadGenerator.Bookmark(siteUrl, "Adres do pilota"); QRCodeData qrCodeData = qrGenerator.CreateQrCode(bookmark); BitmapByteQRCode qrCode = new BitmapByteQRCode(qrCodeData); byte[] qrCodeBytes = qrCode.GetGraphic(20); return(qrCodeBytes, "image/bmp"); }
public Task <byte[]> Encode(string content, int pixelPerModule = ImagingConstants.DefaultQRCodePixelPerModule) { if (pixelPerModule < ImagingConstants.MinimalQRCodePixelPerModule) { pixelPerModule = ImagingConstants.DefaultQRCodePixelPerModule; } var qrcodeData = this.GetQRCodeData(content); var qrcode = new BitmapByteQRCode(qrcodeData); byte[] qrcodeImage = qrcode.GetGraphic(pixelPerModule); return(Task.FromResult(qrcodeImage)); }
private async void ShareBtn_Clicked(object sender, RoutedEventArgs e) { var btn = sender as MenuFlyoutItem; var shareurl = "http://www.super.cn/d/index.php?t=1&i={0}&p=1&v=7.8.4&y={1}&tm={2}"; shareurl = string.Format(shareurl, Class.UserManager.UserData.id, Class.UserManager.UserData.beginYear, Class.UserManager.UserData.term); switch (btn.TabIndex) { case 2: QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(new PayloadGenerator.Url(shareurl).ToString(), QRCodeGenerator.ECCLevel.H); BitmapByteQRCode qrCode = new BitmapByteQRCode(qrCodeData); qrdata = qrCode.GetGraphic(50); using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream()) { using (DataWriter writer = new DataWriter(stream.GetOutputStreamAt(0))) { writer.WriteBytes(qrdata); await writer.StoreAsync(); } var image = new BitmapImage(); await image.SetSourceAsync(stream); qrimage.Source = image; } var res = await qrcode_dialig.ShowAsync(); if (res == ContentDialogResult.Primary) { DataTransferManager.ShowShareUI(); } else if (res == ContentDialogResult.Secondary) { var qrfile = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync("friday-" + Class.HttpPostUntil.NowTime + ".png", CreationCollisionOption.ReplaceExisting); await FileIO.WriteBytesAsync(qrfile, qrdata); Class.Tools.ShowMsgAtFrame("二维码已保存到图片库"); } break; case 3: DataTransferManager.ShowShareUI(); break; default: break; } }
/// <summary> /// A simple function that takes a string and does a ToUpper /// </summary> /// <param name="input"></param> /// <param name="context"></param> /// <returns></returns> public async Task FunctionHandler(string input, ILambdaContext context) { s3Client = new AmazonS3Client(bucketRegion); var fileTransferUtility = new TransferUtility(s3Client); var dbClient = new AmazonDynamoDBClient(); var request = new ScanRequest { TableName = "Tag", ProjectionExpression = "tagId", ExpressionAttributeValues = new Dictionary <string, AttributeValue> { { ":catg", new AttributeValue { BOOL = false } } }, ExpressionAttributeNames = new Dictionary <string, string> { { "#printed", "printed" } }, FilterExpression = "#printed = :catg" }; var response = await dbClient.ScanAsync(request); foreach (var item in response.Items) { var value = new AttributeValue(); item.TryGetValue("tagId", out value); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode($"https://petzfinder.net/tag/{ value.S }", QRCodeGenerator.ECCLevel.Q);; BitmapByteQRCode qrCode = new BitmapByteQRCode(qrCodeData); var bitmap = qrCode.GetGraphic(2); var stream = new MemoryStream(bitmap); try { await fileTransferUtility.UploadAsync(stream, bucketName, $"{value.S}.png"); } catch (AmazonS3Exception e) { Console.WriteLine("Error encountered on server. Message:'{0}' when writing an object", e.Message); } catch (Exception e) { Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", e.Message); } } }
public byte[] GetQrCodeBytes(Reservation reservation) { if (reservation == null) { throw new ArgumentNullException(nameof(reservation)); } var qrGenerator = new QRCodeGenerator(); var qrCodeData = qrGenerator.CreateQrCode(reservation.ToString(), QRCodeGenerator.ECCLevel.Q); var qrCode = new BitmapByteQRCode(qrCodeData); var qrCodeAsBitmapByteArr = qrCode.GetGraphic(20); return(qrCodeAsBitmapByteArr); }