Advertisement
Guest User

fuhq yu

a guest
Mar 27th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using ZXing;
  11. using ZXing.Common;
  12. using ZXing.QrCode;
  13.  
  14. // **** PACKAGE MANAGAER CONSOLE
  15. // **** Install-Package ZXing.Net
  16.  
  17. namespace BarCodes
  18. {
  19.     public partial class Form1 : Form
  20.     {
  21.         public Form1()
  22.         {
  23.             InitializeComponent();
  24.         }
  25.  
  26.         private void Form1_Load(object sender, EventArgs e)
  27.         {
  28.             radioButtonQR.Checked = true;
  29.             radioButtonBC.Checked = false;
  30.         }
  31.  
  32.         private void buttonConvert_Click(object sender, EventArgs e)
  33.         {
  34.             if (textBox.Text.Length == 0)
  35.             {
  36.                 pictureBoxQR.Image = null;
  37.                 return;
  38.             }
  39.             var options = new QrCodeEncodingOptions
  40.             {
  41.                 DisableECI = true,
  42.                 CharacterSet = "UTF-8",
  43.                 Width = 500,
  44.                 Height = 500,
  45.             };
  46.  
  47.             var qr = new ZXing.BarcodeWriter();
  48.  
  49.             qr.Options = options;
  50.             if(radioButtonQR.Checked)
  51.                 qr.Format = BarcodeFormat.QR_CODE;
  52.             else
  53.                 qr.Format = BarcodeFormat.CODE_128;
  54.             var result = new Bitmap(qr.Write(textBox.Text.Trim()));
  55.             //"result" can also be used when printing QR Codes.
  56.             //R:\Computer Science\Y13\Printing
  57.  
  58.             pictureBoxQR.Image = result;
  59.         }
  60.     }
  61.    
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement