C # Notes for generating qrcode QR codes

Source: Internet
Author: User

First of all, the source code http://www.codeproject.com/Articles/20574/Open-Source-QRCode-Library of C # qrcode

Then you need to modify someCodeUsed to support Chinese Characters

You may encounter problems when modifying the code.

Question 1 (I have encountered this problem ):

When debugging the winform platform, the following error occurs: 'thoughtworks. qrcode. properties. resources' 'does not contain a definition for 'getresource '.

Change the error location to memorystream = new memorystream (byte []) resources. ResourceManager. GetObject (filename ));
You can.

Question 2:

Example of debugging WmProgramIn encode, an exception occurs when indexoutofrangeexception in rstemp exceeds the maximum index value. The exception is thrown in rstemp [rsblocknumber] [J] = codewords [I2 ~
I thought it was a program logic error. After comparing the desktop and WM class libraries, I found that there was no error. Then I finally found a stupid solution:
I noticed that in the qrcodeencoder. CS class under the qrcodecancelib project,:
Internal static string data_path = "qrcode_data ";
This line of code has been commented out on the desktop version. I guess I want to copy the resource file to this directory of the WM program? Well, create a new folder named qrcode_data under the qrcodewindowsmobile5 project, and then copy the resource files to this directory.
Set the generation action of these resource files to (Copy copy, content), and then re-debug, encode ~ Pass!

Supported Chinese characters for modification:

Modify qrcodeencoder. Cs in the qrcodelib Library

 

 
Public Virtual bitmap encode (string content) {If (qrcodeutility. isunicode (content) {return encode (content, encoding. unicode);} else {return encode (content, encoding. ASCII );}}

 

Is

 

Public Virtual bitmap encode (string content) {If (qrcodeutility. isunicode (content) {return encode (content, encoding. getencoding ("gb2312");} else {return encode (content, encoding. ASCII );}}

 

The corresponding code in the qrcodedecoder. CS class also needs to be modified. In this way, both Chinese and English are supported.

Extension

1. Modify qrcodeencoder. CS and qrcodedecoder. CS

Search and convert encoding. Unicode to encoding. utf8.

2. Modify qrcodeutility. CS

Set unicodeencoding encoding = new unicodeencoding ();

Changed to utf8encoding encoding = new utf8encoding ();

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.