public ActionResult QR_Button_Click(string LessonCode) { QRCodeGenerator qrgenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrgenerator.CreateQrCode(LessonCode, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); System.Web.UI.WebControls.Image imgQRcode = new System.Web.UI.WebControls.Image(); imgQRcode.Width = 500; imgQRcode.Height = 500; using (Bitmap qrCodeImage = qrCode.GetGraphic(20)) { using (MemoryStream ms = new MemoryStream()) { qrCodeImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] byteImage = ms.ToArray(); imgQRcode.ImageUrl = "data:image/png;base64, " + Convert.ToBase64String(byteImage); } ViewData["QRCodeImage"] = imgQRcode.ImageUrl; imgQRcode.Dispose(); qrCodeData.Dispose(); qrgenerator.Dispose(); qrCode.Dispose(); qrCodeData.Dispose(); return(View("TestQR")); } }
private void GenerateGeoLocationQr(string lat, string longi) { try { Geolocation generator = new Geolocation(lat, longi); string payload = generator.ToString(); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); var qrCodeAsBitmap = qrCode.GetGraphic(20); if (save_image_geo) { using (FolderBrowserDialog f = new FolderBrowserDialog()) { if (f.ShowDialog() == DialogResult.OK) { qrCodeAsBitmap.Save(Path.Combine(f.SelectedPath, "qr-code-geolocation.png")); } } } GeoPic.Image = qrCodeAsBitmap; qrGenerator.Dispose(); qrCode.Dispose(); qrCodeData.Dispose(); } catch (Exception) { throw; } }
private void GenerateQRForBookMark(string name, string url) { Bookmark generator = new Bookmark(url, name); string payload = generator.ToString(); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); Bitmap qrCodeAsBitmap = qrCode.GetGraphic(20); if (save_image_book == true) { using (FolderBrowserDialog f = new FolderBrowserDialog()) { if (f.ShowDialog() == DialogResult.OK) { qrCodeAsBitmap.Save(Path.Combine(f.SelectedPath, "qr-code-bookmark.png")); } } } bookPicture.Image = qrCodeAsBitmap; qrGenerator.Dispose(); qrCode.Dispose(); qrCodeData.Dispose(); }
private void GenerateQRForUrl(string url) { try { Url generator = new Url(url); string payload = generator.ToString(); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); Bitmap qrCodeAsBitmap = qrCode.GetGraphic(20); if (save_image_url == true) { using (FolderBrowserDialog f = new FolderBrowserDialog()) { if (f.ShowDialog() == DialogResult.OK) { qrCodeAsBitmap.Save(Path.Combine(f.SelectedPath, "qr-code-url.png")); } } } pictureBoxUrl.Image = qrCodeAsBitmap; qrCode.Dispose(); qrCodeData.Dispose(); qrGenerator.Dispose(); } catch (Exception e) { MetroSetMessageBox.Show(this, "An error : " + e.Message, "QR Creator"); } }
private void GenerateQRFromText(string text) { try { // Creating the elements here QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(text, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrCode.GetGraphic(20); // If user checks the check box saves the image with default name if (save_image_text == true) { using (FolderBrowserDialog f = new FolderBrowserDialog()) { if (f.ShowDialog() == DialogResult.OK) { qrCodeImage.Save(Path.Combine(f.SelectedPath, "qr-code-text.png")); } } } // show image pictureBoxText.Image = qrCodeImage; // free ram qrGenerator.Dispose(); qrCodeData.Dispose(); qrCode.Dispose(); } //If ex is catched displat //TODO : Custom Mess // Not more showing the message but an fix for this error catch (Exception e) { MetroSetMessageBox.Show(this, "An error : " + e.Message, "QR Creator"); } }
private void GenerateQRForWifi(string name, string password, string auth) { try { using (FolderBrowserDialog f = new FolderBrowserDialog()) { // if this is empty then this will not execute : // TODO : Check the pass only on WPA or WEP if (auth == "nopass") { WiFi generator = new WiFi(name, password, WiFi.Authentication.nopass); string payload = generator.ToString(); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); Bitmap qrCodeAsBitmap = qrCode.GetGraphic(20); if (save_image_wifi == true) { if (f.ShowDialog() == DialogResult.OK) { qrCodeAsBitmap.Save(Path.Combine(f.SelectedPath, "qr-code-wifi-no-pass.png")); } } pictureBoxWifi.Image = qrCodeAsBitmap; //free ram qrGenerator.Dispose(); qrCodeData.Dispose(); qrCode.Dispose(); Clear(); } else if (auth == "WPA") { WiFi generator = new WiFi(name, password, WiFi.Authentication.WPA); string payload = generator.ToString(); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); Bitmap qrCodeAsBitmap = qrCode.GetGraphic(20); if (save_image_wifi == true) { if (f.ShowDialog() == DialogResult.OK) { qrCodeAsBitmap.Save(Path.Combine(f.SelectedPath, "qr-code-wifi-pass.png")); } } pictureBoxWifi.Image = qrCodeAsBitmap; qrGenerator.Dispose(); qrCodeData.Dispose(); qrCode.Dispose(); Clear(); } else if (auth == "WEP") { WiFi generator = new WiFi(name, password, WiFi.Authentication.WEP); string payload = generator.ToString(); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); Bitmap qrCodeAsBitmap = qrCode.GetGraphic(20); if (save_image_wifi == true) { if (f.ShowDialog() == DialogResult.OK) { qrCodeAsBitmap.Save(Path.Combine(f.SelectedPath, "qr-code-wifi-pass.png")); } } pictureBoxWifi.Image = qrCodeAsBitmap; qrGenerator.Dispose(); qrCodeData.Dispose(); qrCode.Dispose(); Clear(); } } } catch (Exception e) { MetroSetMessageBox.Show(this, "An error : " + e.Message, "QR Creator"); } }