: http://zxingnet.codeplex.com/
Zxing.net is a tool for barcode and QR code under the. NET platform, which is very convenient to use.
First download the binary DLL file, introduce the project;
Code:
C # code
- Using System;
- Using System.Collections.Generic;
- Using System.ComponentModel;
- Using System.Data;
- Using System.Drawing;
- Using System.Text;
- Using System.Windows.Forms;
- Using Zxing.qrcode;
- Using ZXing;
- Using Zxing.common;
- Using Zxing.rendering;
- Namespace Zxingtest
- {
- Public partial class Form1:form
- {
- Encodingoptions options = null;
- Barcodewriter writer = null;
- Public Form1 ()
- {
- InitializeComponent ();
- options = New Qrcodeencodingoptions
- {
- Disableeci = true,
- CharacterSet = "UTF-8",
- Width = Pictureboxqr.width,
- Height = Pictureboxqr.height
- };
- writer = new Barcodewriter ();
- Writer. Format = Barcodeformat.qr_code;
- Writer. options = options;
- }
- private void Buttonqr_click (object sender, EventArgs e)
- {
- if (Textboxtext.text = = string. Empty)
- {
- MessageBox.Show ("The input cannot be empty!") ");
- return;
- }
- Bitmap Bitmap = writer. Write (Textboxtext.text);
- Pictureboxqr.image = bitmap;
- }
- }
- }
Effect:
Character formatting can be specified when characters are encoded, the default is iso-8859-1 English character set, but generally mobile devices commonly used UTF-8 character set encoding,
Encoding can be set by Qrcodeencodingoptions.
If you want to generate additional zxing-supported barcodes, just modify the Barcodewriter.format.
C # code
- Using System;
- Using System.Collections.Generic;
- Using System.ComponentModel;
- Using System.Data;
- Using System.Drawing;
- Using System.Text;
- Using System.Windows.Forms;
- Using Zxing.qrcode;
- Using ZXing;
- Using Zxing.common;
- Using Zxing.rendering;
- Namespace Zxingtest
- {
- Public partial class Form1:form
- {
- Encodingoptions options = null;
- Barcodewriter writer = null;
- Public Form1 ()
- {
- InitializeComponent ();
- options = New Encodingoptions
- {
- //disableeci = True,
- //characterset = "UTF-8",
- Width = Pictureboxqr.width,
- Height = Pictureboxqr.height
- };
- writer = new Barcodewriter ();
- Writer. Format = BARCODEFORMAT.ITF;
- Writer. options = options;
- }
- private void Buttonqr_click (object sender, EventArgs e)
- {
- if (Textboxtext.text = = string. Empty)
- {
- MessageBox.Show ("The input cannot be empty!") ");
- return;
- }
- Bitmap Bitmap = writer. Write (Textboxtext.text);
- Pictureboxqr.image = bitmap;
- }
- }
- }
Effect:
The input string needs to conform to the encoded format, or it will error. Decoding method: C # code
- Using System;
- Using System.Collections.Generic;
- Using System.ComponentModel;
- Using System.Data;
- Using System.Drawing;
- Using System.Text;
- Using System.Windows.Forms;
- Using Zxing.qrcode;
- Using ZXing;
- Using Zxing.common;
- Using Zxing.rendering;
- Namespace Zxingtest
- {
- Public partial class Form1:form
- {
- Barcodereader reader = null;
- Public Form1 ()
- {
- InitializeComponent ();
- reader = new Barcodereader ();
- }
- private void Form1_dragenter (object sender, DragEventArgs e)//When drag and drop into form
- {
- if (e.data.getdatapresent (dataformats.filedrop))
- E.effect = dragdropeffects.copy; //Show copy effect
- Else
- E.effect = DragDropEffects.None;
- }
- private void Form1_dragdrop (object sender, DragEventArgs e) //When dragged and placed on a form
- {
- string[] FileNames = (string[]) e.data.getdata (DataFormats.FileDrop, false); //Get file name
- if (filenames.length > 0)
- {
- Pictureboxpic.load (Filenames[0]); //Show Pictures
- Result result = reader. Decode ((Bitmap) pictureboxpic.image); //decoding via reader
- Textboxtext.text = result. Text; //Show analytic results
- }
- }
- }
- }
- Zxingdecoder.zip (401.4 KB)
- Download number of times: 117
- Zxingencoder.zip (395.8 KB)
- Download number of times: 106
C # uses zxing.net to operate QR codes and barcodes