日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯網營銷解決方案
如何用.NET生成二維碼?

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

站在用戶的角度思考問題,與客戶深入溝通,找到路橋網站設計與路橋網站推廣的解決方案,憑借多年的經驗,讓設計與互聯網技術結合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:網站設計制作、網站建設、企業(yè)官網、英文網站、手機端網站、網站推廣、主機域名、網站空間、企業(yè)郵箱。業(yè)務覆蓋路橋地區(qū)。

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

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

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

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

圖形如下所示:

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. namespace WinQRCode
  10. {
  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.         /// 
  23.         /// 編碼
  24.         /// 
  25.         /// 
  26.         /// 
  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.         /// 解碼
  53.         /// 
  54.         /// 
  55.         /// 
  56.         private void button2_Click(object sender, EventArgs e)
  57.         {
  58.             Cursor.Current = Cursors.WaitCursor;
  59.             Bitmap b = this.pictureBox1.Image as Bitmap;
  60.             try
  61.             {
  62.                 QRCodeDecoder decoder = new QRCodeDecoder();
  63.                 //解碼
  64.                 String decodedString = decoder.decode(new QRCodeBitmapImage(b));
  65.                 //顯示解碼信息
  66.                 this.lbl解碼信息.Text += decodedString ;
  67.             }
  68.             catch (Exception ex)
  69.             {
  70.                 MessageBox.Show(ex.Message);
  71.             }
  72.             Cursor.Current = Cursors.Default;
  73.         }
  74.         private void Form1_Load(object sender, EventArgs e)
  75.         {
  76.         }
  77.     }
  78. }

4、編譯運行,如下圖:

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


本文名稱:如何用.NET生成二維碼?
文章鏈接:http://www.5511xx.com/article/cohoecd.html