Asp.net C # instance code for generating and parsing QR codes

Source: Internet
Author: User

The class library file is downloaded at the end of the file.

[ThoughtWorks. QRCode. dll is the class library]

You need to add:
Copy codeThe Code is as follows:
Using ThoughtWorks. QRCode. Codec;

Using ThoughtWorks. QRCode. Codec. Data;

Using ThoughtWorks. QRCode. Codec. Util;

Main source code:

1. Generate a QR code

Copy codeThe Code is as follows:
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder ();
String encoding = cboEncoding. Text;
If (encoding = "Byte ")
{
QrCodeEncoder. QRCodeEncodeMode = QRCodeEncoder. ENCODE_MODE.BYTE;
}
Else if (encoding = "AlphaNumeric ")
{
QrCodeEncoder. QRCodeEncodeMode = QRCodeEncoder. ENCODE_MODE.ALPHA_NUMERIC;
}
Else if (encoding = "Numeric ")
{
QrCodeEncoder. QRCodeEncodeMode = QRCodeEncoder. ENCODE_MODE.NUMERIC;
}
Try
{
Int scale = Convert. ToInt16 (txtSize. Text );
QrCodeEncoder. QRCodeScale = scale;
}
Catch (Exception ex)
{
MessageBox. Show ("Invalid size! ");
Return;
}
Try
{
Int version = Convert. ToInt16 (cboVersion. Text );
QrCodeEncoder. QRCodeVersion = version;
}
Catch (Exception ex)
{
MessageBox. Show ("Invalid version! ");
}

String errorCorrect = cboCorrectionLevel. Text;
If (errorCorrect = "L ")
QrCodeEncoder. QRCodeErrorCorrect = QRCodeEncoder. ERROR_CORRECTION.L;
Else if (errorCorrect = "M ")
QrCodeEncoder. QRCodeErrorCorrect = QRCodeEncoder. ERROR_CORRECTION.M;
Else if (errorCorrect = "Q ")
QrCodeEncoder. QRCodeErrorCorrect = QRCodeEncoder. ERROR_CORRECTION.Q;
Else if (errorCorrect = "H ")
QrCodeEncoder. QRCodeErrorCorrect = QRCodeEncoder. ERROR_CORRECTION.H;
Image image;
String data = txtEncodeData. Text;
Image = qrCodeEncoder. Encode (data );
Pb_view.Image = image;

2. parse the QR code
Copy codeThe Code is as follows:
QRCodeDecoder decoder = new QRCodeDecoder ();
String decodedString = decoder. decode (new QRCodeBitmapImage (new Bitmap (pb_view.Image )));
TxtEncodeData. Text = decodedString;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.