public void Dispose() { if (generator != null) { generator.Dispose(); } }
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"); } }
/// <summary> /// 生成单个二维码 /// </summary> /// <param name="subProjectId"></param> /// <param name="pixel"></param> /// <returns></returns> public Task <string> SaveQrCode(Guid subProjectId, int pixel = 4) { var generator = new QRCodeGenerator(); var filePath = GetQrCodePath(subProjectId); // 如果存在就不生成 if (File.Exists(filePath)) { return(Task.FromResult(filePath)); } // 生成二维码 // var url = "https://dotnet.holacodes.com/app/home/relational-info?id=" + subProjectId; // 获取租户信息 var tenantId = CurrentUnitOfWork.GetTenantId(); var tenancyName = tenantId.HasValue ? _tenantManager.GetById((int)tenantId).TenancyName : null; // 在url里面填入租户名字 var url = $"https://dotnet.holacodes.com/public;tenancyName={tenancyName}/relational-info?id=" + subProjectId; var qrCode = new QRCode(generator.CreateQrCode(url, QRCodeGenerator.ECCLevel.M, true)); var bitmap = qrCode.GetGraphic(pixel, Color.Black, Color.White, true); bitmap.Save(filePath, ImageFormat.Jpeg); // 释放资源 qrCode.Dispose(); bitmap.Dispose(); generator.Dispose(); return(Task.FromResult(filePath)); }
/// <inheritdoc/> protected override ValueTask DisposeAsync(bool disposing) { if (disposing) { generator?.Dispose(); } return(base.DisposeAsync(disposing)); }
private void button1_Click(object sender, EventArgs e) { Image barCodeImage = myBarcode.Encode(BarcodeLib.TYPE.CODE128, textBox1_barcode.Text); pictureBox_BarCode.Image = barCodeImage; QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCode qrCode = new QRCode(qrGenerator.CreateQrCode(textBox2_qrcode.Text, QRCodeGenerator.ECCLevel.Q)); pictureBox_QRCode.Image = qrCode.GetGraphic(2, Color.Black, Color.White, false); qrGenerator.Dispose(); qrCode.Dispose(); }
public static Image QRCodeImage(string data) { Image picQRCode; QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCode qrCode = new QRCode(qrGenerator.CreateQrCode(data, QRCodeGenerator.ECCLevel.Q)); picQRCode = qrCode.GetGraphic(8, Color.Black, Color.White, false); qrGenerator.Dispose(); qrCode.Dispose(); return(picQRCode); }
//二维码文本 -> 二维码图片 private void getQRCodeImg(string qrCodeText, int pixelPerModel, string imgPath) { //QRCodeData qRCodeData = ; QRCodeGenerator qRCodeGenerator = new QRCodeGenerator(); QRCode qrCode = new QRCode(qRCodeGenerator.CreateQrCode(qrCodeText, QRCodeGenerator.ECCLevel.M)); //Bitmap qrCodeImg = qrCode.GetGraphic(pixelPerModel); qrCode.GetGraphic(pixelPerModel, Color.Black, Color.White, false).Save(imgPath); //qrCodeImg.Save(imgPath); qRCodeGenerator.Dispose(); qrCode.Dispose(); }
void loadQR() { for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { QRCodeGenerator qr = new QRCodeGenerator(); string Name = dataGridView1.Rows[i].Cells[1].Value.ToString(); QRCode qrC = new QRCode(qr.CreateQrCode(Name, QRCodeGenerator.ECCLevel.Q)); Image QR = qrC.GetGraphic(2, Color.Black, Color.White, false); imageListName.Images.Add(QR); listView2.Items.Add(Name, i); qr.Dispose(); qrC.Dispose(); } listView2.LargeImageList = imageListName; }
public byte[] GenQR(PKM pokemon) { try { string data = QRMessageUtil.GetMessage(pokemon); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(data, QRCodeGenerator.ECCLevel.L); PngByteQRCode qrCode = new PngByteQRCode(qrCodeData); byte[] qrCodeAsPngByteArr = qrCode.GetGraphic(3); qrCode.Dispose(); qrGenerator.Dispose(); return(qrCodeAsPngByteArr); } catch (Exception e) { Console.WriteLine(e.ToString()); return(null); } }
/// <summary> /// 批量生成二维码并下载,要把生成和下载分开的原因是:在文件下载的位置查询数据库,不建议这样做 /// </summary> /// <param name="subProjectIds"></param> /// <param name="pixel"></param> /// <returns></returns> public Task SaveQrCodes(IEnumerable <Guid> subProjectIds, int pixel = 4) { var generator = new QRCodeGenerator(); // 生成二维码,操作时间较长,获取hash名字做临时文件夹 var hashName = MD5.Create().ComputeHash(Encoding.Default.GetBytes(DateTime.Now.ToLongTimeString())) .ToString(); var qrFolderPath = Path.Join(_hostingEnvironment.ContentRootPath, FileItemManager.FileItemsPath, hashName); Directory.CreateDirectory(qrFolderPath); foreach (var id in subProjectIds) { // var url = "https://dotnet.holacodes.com/app/home/relational-info?id=" + id; // 获取租户信息 var tenantId = CurrentUnitOfWork.GetTenantId(); var tenancyName = tenantId.HasValue ? _tenantManager.GetById((int)tenantId).TenancyName : null; // 在url里面填入租户名字 var url = $"https://dotnet.holacodes.com/public;tenancyName={tenancyName}/relational-info?id=" + id; var qrCode = new QRCode(generator.CreateQrCode(url, QRCodeGenerator.ECCLevel.M, true)); var bitmap = qrCode.GetGraphic(pixel, Color.Black, Color.White, true); bitmap.Save(Path.Join(qrFolderPath, id + ".jpg"), ImageFormat.Jpeg); qrCode.Dispose(); bitmap.Dispose(); } generator.Dispose(); // 创建压缩文件 var qrZipFile = GetQrCodesZipPath(); if (File.Exists(qrZipFile)) { File.Delete(qrZipFile); } System.IO.Compression.ZipFile.CreateFromDirectory(qrFolderPath, qrZipFile); // 删除临时文件 if (Directory.Exists(qrFolderPath)) { Directory.Delete(qrFolderPath, true); } return(Task.CompletedTask); }
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"); } }
public void Dispose() { Instance.Dispose(); }
public void Dispose() => generator.Dispose();
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"); } }