成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

如何用.NET生成二維碼?

開發 后端
二維碼是用某種特定的幾何圖形按一定規律在平面(二維方向上)分布的黑白相間的圖形記錄數據符號信息的,國外對二維碼技術的研究始于20世紀80年代 末,在二維碼符號表示技術研究方面已研制出多種碼制。

二維碼是用某種特定的幾何圖形按一定規律在平面(二維方向上)分布的黑白相間的圖形記錄數據符號信息的,國外對二維碼技術的研究始于20世紀80年代 末,在二維碼符號表示技術研究方面已研制出多種碼制,常見的有PDF417、QR Code、Code 49、Code 16K、Code One等。二維碼技術已經被廣泛應用于公安、外交、軍事等部門對各類證件的管理,而且也將二維碼應用于海關、稅務等部門對各類報表和票據的管理,商業、交 通運輸等部門對商品及貨物運輸的管理、郵政部門對郵政包裹的管理、工業生產領域對工業生產線的自動化管理。

下面介紹一下如何用.NET生成二維碼(QR Code碼制),下面給出詳細步驟:

1、新建一個window應用程序,然后引入.NET二維碼類庫(開源的類庫,可從網上下載):

2、構建UI界面,代碼如下:

  1. namespace WinQRCode 
  2.     partial class Form1 
  3.     { 
  4.         /// <summary> 
  5.         /// 必需的設計器變量。 
  6.         /// </summary> 
  7.         private System.ComponentModel.IContainer components = null
  8.  
  9.         /// <summary> 
  10.         /// 清理所有正在使用的資源。 
  11.         /// </summary> 
  12.         /// <param name="disposing">如果應釋放托管資源,為 true;否則為 false。</param> 
  13.         protected override void Dispose(bool disposing) 
  14.         { 
  15.             if (disposing && (components != null)) 
  16.             { 
  17.                 components.Dispose(); 
  18.             } 
  19.             base.Dispose(disposing); 
  20.         } 
  21.  
  22.         #region Windows 窗體設計器生成的代碼 
  23.  
  24.         /// <summary> 
  25.         /// 設計器支持所需的方法 - 不要 
  26.         /// 使用代碼編輯器修改此方法的內容。 
  27.         /// </summary> 
  28.         private void InitializeComponent() 
  29.         { 
  30.             this.button1 = new System.Windows.Forms.Button(); 
  31.             this.button2 = new System.Windows.Forms.Button(); 
  32.             this.pictureBox1 = new System.Windows.Forms.PictureBox(); 
  33.             this.label1 = new System.Windows.Forms.Label(); 
  34.             this.textBox1 = new System.Windows.Forms.TextBox(); 
  35.             this.label2 = new System.Windows.Forms.Label(); 
  36.             this.lbl解碼信息 = new System.Windows.Forms.Label(); 
  37.             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); 
  38.             this.SuspendLayout(); 
  39.             //  
  40.             // button1 
  41.             //  
  42.             this.button1.Location = new System.Drawing.Point(44631); 
  43.             this.button1.Margin = new System.Windows.Forms.Padding(4545); 
  44.             this.button1.Name = "button1"
  45.             this.button1.Size = new System.Drawing.Size(10337); 
  46.             this.button1.TabIndex = 0
  47.             this.button1.Text = "編碼"
  48.             this.button1.UseVisualStyleBackColor = true
  49.             this.button1.Click += new System.EventHandler(this.button1_Click); 
  50.             //  
  51.             // button2 
  52.             //  
  53.             this.button2.Location = new System.Drawing.Point(44681); 
  54.             this.button2.Margin = new System.Windows.Forms.Padding(4545); 
  55.             this.button2.Name = "button2"
  56.             this.button2.Size = new System.Drawing.Size(10337); 
  57.             this.button2.TabIndex = 1
  58.             this.button2.Text = "解碼"
  59.             this.button2.UseVisualStyleBackColor = true
  60.             this.button2.Click += new System.EventHandler(this.button2_Click); 
  61.             //  
  62.             // pictureBox1 
  63.             //  
  64.             this.pictureBox1.Location = new System.Drawing.Point(23117); 
  65.             this.pictureBox1.Margin = new System.Windows.Forms.Padding(4545); 
  66.             this.pictureBox1.Name = "pictureBox1"
  67.             this.pictureBox1.Size = new System.Drawing.Size(279253); 
  68.             this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; 
  69.             this.pictureBox1.TabIndex = 2
  70.             this.pictureBox1.TabStop = false
  71.             //  
  72.             // label1 
  73.             //  
  74.             this.label1.AutoSize = true
  75.             this.label1.Location = new System.Drawing.Point(1839); 
  76.             this.label1.Margin = new System.Windows.Forms.Padding(4040); 
  77.             this.label1.Name = "label1"
  78.             this.label1.Size = new System.Drawing.Size(6925); 
  79.             this.label1.TabIndex = 3
  80.             this.label1.Text = "信息:"
  81.             //  
  82.             // textBox1 
  83.             //  
  84.             this.textBox1.Location = new System.Drawing.Point(9537); 
  85.             this.textBox1.Margin = new System.Windows.Forms.Padding(4545); 
  86.             this.textBox1.Name = "textBox1"
  87.             this.textBox1.Size = new System.Drawing.Size(33331); 
  88.             this.textBox1.TabIndex = 4
  89.             //  
  90.             // label2 
  91.             //  
  92.             this.label2.AutoSize = true
  93.             this.label2.Location = new System.Drawing.Point(1881); 
  94.             this.label2.Margin = new System.Windows.Forms.Padding(4040); 
  95.             this.label2.Name = "label2"
  96.             this.label2.Size = new System.Drawing.Size(8825); 
  97.             this.label2.TabIndex = 5
  98.             this.label2.Text = "二維碼:"
  99.             //  
  100.             // lbl解碼信息 
  101.             //  
  102.             this.lbl解碼信息.AutoSize = true
  103.             this.lbl解碼信息.Location = new System.Drawing.Point(10181); 
  104.             this.lbl解碼信息.Margin = new System.Windows.Forms.Padding(4040); 
  105.             this.lbl解碼信息.Name = "lbl解碼信息"
  106.             this.lbl解碼信息.Size = new System.Drawing.Size(025); 
  107.             this.lbl解碼信息.TabIndex = 6
  108.             //  
  109.             // Form1 
  110.             //  
  111.             this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F); 
  112.             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
  113.             this.ClientSize = new System.Drawing.Size(572384); 
  114.             this.Controls.Add(this.lbl解碼信息); 
  115.             this.Controls.Add(this.label2); 
  116.             this.Controls.Add(this.textBox1); 
  117.             this.Controls.Add(this.label1); 
  118.             this.Controls.Add(this.pictureBox1); 
  119.             this.Controls.Add(this.button2); 
  120.             this.Controls.Add(this.button1); 
  121.             this.Font = new System.Drawing.Font("微軟雅黑"10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 
  122.             this.Margin = new System.Windows.Forms.Padding(4545); 
  123.             this.Name = "Form1"
  124.             this.Text = "二維碼"
  125.             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); 
  126.             this.ResumeLayout(false); 
  127.             this.PerformLayout(); 
  128.  
  129.         } 
  130.  
  131.         #endregion 
  132.  
  133.         private System.Windows.Forms.Button button1; 
  134.         private System.Windows.Forms.Button button2; 
  135.         private System.Windows.Forms.PictureBox pictureBox1; 
  136.         private System.Windows.Forms.Label label1; 
  137.         private System.Windows.Forms.TextBox textBox1; 
  138.         private System.Windows.Forms.Label label2; 
  139.         private System.Windows.Forms.Label lbl解碼信息; 
  140.     } 

圖形如下所示:

3、編寫 編碼和解碼按鈕事件,進行編碼和解碼處理:

  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.Windows.Forms; 
  9.  
  10. namespace WinQRCode 
  11.     using ThoughtWorks.QRCode.Codec; 
  12.     using ThoughtWorks.QRCode.Codec.Data; 
  13.     using ThoughtWorks.QRCode.Codec.Util; 
  14.     using System.IO; 
  15.     using PdfToImage; 
  16.     public partial class Form1 : Form 
  17.     { 
  18.         public Form1() 
  19.         { 
  20.             InitializeComponent(); 
  21.         } 
  22.         /// <summary> 
  23.         /// 編碼 
  24.         /// </summary> 
  25.         /// <param name="sender"></param> 
  26.         /// <param name="e"></param> 
  27.         private void button1_Click(object sender, EventArgs e) 
  28.         { 
  29.             if (this.textBox1.Text != ""
  30.             { 
  31.                 Cursor.Current = Cursors.WaitCursor; 
  32.                 if (textBox1.Text.Trim() == String.Empty) 
  33.                 { 
  34.                     MessageBox.Show("不能為空."); 
  35.                     return
  36.                 } 
  37.                 QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();                
  38.                 qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; 
  39.                 qrCodeEncoder.QRCodeScale = 4
  40.                 qrCodeEncoder.QRCodeVersion = 7;              
  41.                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;                
  42.                 System.Drawing.Image image; 
  43.                 String data = textBox1.Text; 
  44.                 //編碼 
  45.                 image = qrCodeEncoder.Encode(data); 
  46.                 //圖片顯示 
  47.                 this.pictureBox1.Image = image; 
  48.                 Cursor.Current = Cursors.Default; 
  49.  
  50.             } 
  51.         } 
  52.         /// <summary> 
  53.         /// 解碼 
  54.         /// </summary> 
  55.         /// <param name="sender"></param> 
  56.         /// <param name="e"></param> 
  57.         private void button2_Click(object sender, EventArgs e) 
  58.         { 
  59.             Cursor.Current = Cursors.WaitCursor; 
  60.             Bitmap b = this.pictureBox1.Image as Bitmap; 
  61.             try 
  62.             { 
  63.                 QRCodeDecoder decoder = new QRCodeDecoder(); 
  64.                 //解碼 
  65.                 String decodedString = decoder.decode(new QRCodeBitmapImage(b)); 
  66.                 //顯示解碼信息 
  67.                 this.lbl解碼信息.Text += decodedString ; 
  68.             } 
  69.             catch (Exception ex) 
  70.             { 
  71.                 MessageBox.Show(ex.Message); 
  72.             } 
  73.             Cursor.Current = Cursors.Default; 
  74.         } 
  75.  
  76.         private void Form1_Load(object sender, EventArgs e) 
  77.         { 
  78.  
  79.         } 
  80.     } 

4、編譯運行,如下圖:

 水平有限,望各位園友不吝賜教!如果覺得不錯,請瘋狂的點擊推薦和關注!

責任編輯:王雪燕 來源: 博客園
相關推薦

2024-06-26 08:46:45

2023-11-17 09:07:51

.NET生成二維碼識別二維碼

2023-11-17 15:44:06

C++庫生成二維碼

2013-01-30 12:16:49

二維碼NFC近場通訊

2013-03-27 16:13:17

Android開發Android二維碼生QR生成

2023-10-31 08:16:16

Go語言二維碼

2013-10-29 09:46:05

二維碼

2025-03-04 09:15:00

惡意軟件網絡安全郵件釣魚

2014-12-31 15:37:16

二維碼生成掃描

2021-02-08 08:40:00

Zint二維碼開源

2020-08-07 14:18:03

二維碼Go語言編程

2023-10-07 08:06:55

2011-12-06 16:40:45

二維碼快拍二維碼靈動快拍

2015-11-09 13:03:47

JavaServlet創建二維碼

2020-10-26 11:09:42

二維碼網絡犯罪應用安全

2017-02-21 09:17:46

二維碼漏洞

2017-11-21 09:00:15

PHP二維碼LOGO圖像

2015-10-28 13:33:50

二維碼條形碼掃描源碼

2020-10-08 18:48:02

二維碼安全應用安全網絡攻擊

2012-04-01 09:53:13

二維碼
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 色婷婷综合久久久中字幕精品久久 | 欧美v免费 | 99在线精品视频 | 国产视频一区二区在线观看 | 亚洲午夜精品一区二区三区他趣 | 一级在线视频 | 日韩成人高清在线 | 亚洲欧美一区二区三区情侣bbw | 波多野结衣在线观看一区二区三区 | 亚洲国产一 | 久色一区 | 久久激情网 | 91精品国产综合久久久久久蜜臀 | 秋霞性生活 | 成人伊人 | 欧美在线看片 | 国内av在线 | 一区二区在线免费观看 | 久久免费精品视频 | 一区二区在线不卡 | 一区二区三区日 | 在线看91| va精品 | 亚洲一区二区在线电影 | 精品无码久久久久久国产 | 久久久久久国产精品免费免费狐狸 | 午夜欧美 | 91精品综合久久久久久五月天 | 韩日视频在线观看 | 欧美一区二区三区在线观看 | 国产福利二区 | 二区中文字幕 | 日韩av啪啪网站大全免费观看 | 作爱视频免费观看 | 亚洲精品一级 | 国产精品视频网 | 免费毛片网 | 久久精品国产久精国产 | 免费国产成人av | 日韩在线视频观看 | 伊人春色在线 |