C#生成二維代碼實例

Click here to Skip to main content

 
Licence CPOL
First Posted 20 Sep 2007
Views 233,484
Bookmarked 134 times
Tags 

Open Source QRCode Library

By twit88 | 20 Sep 2007
How to use QRCode library to encode and decode QRCode
Screenshot - qrcode_app_decode.jpg

Introduction

In this article, I will briefly describe the functionalities of the QRCode library.

Background

QRCode library is a .NET component that can be used to encode and decode QRCode. QRCode is a 2 dimensional bar code that originated in Japan. Nowadays, it is widely used in a wide range of industries, e.g. for vehicle parts tracking and inventory management.

QR stands for "Quick Response". It was created by the Japanese corporation Denso-Wave in 1994 and is aimed at decoding contents at high speed. Nowadays, QR Code is used in mobile phones to ease data entry.

QRCode can also be printed on a business card or shown on any display, which can then be captured by the mobile phone provided the mobile phone has the software to read QRCode.

QRCode library provides functions to:

  1. Encode content into a QR Code image which can be saved in JPEG, GIF, PNG, or Bitmap formats
  2. Decode a QR Code image

Using the Code

The library can be used in any .NET 2.0 Windows Application, ASP.NET Web application or Windows Mobile device application.

Some sample screenshots are displayed below:

Screenshot - qrcode_app_encode.jpg

Screenshot - qrcode_mobile_encode.jpg

Collapse | Copy Code
  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);                                  picEncode.Image = image;

History

  • 20th September, 2007: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

twit88

Web Developer
 
Malaysia Malaysia

Member
A programmer for a long time, and still learning everyday.

A supporter for open source solutions, and have written quite a few open source software both in .NET and Java.

Homepage
http://twit88.com/home

Blog
http://twit88.com/blog

Sign Up to vote for this article
 
Add a reason or comment to your vote: x

Comments and Discussions

You must Sign In to use this message board.
FAQ FAQ  
Noise ToleranceVery HighHighMediumLowVery Low  LayoutNormalExpand Posts onlyExpand Posts & RepliesThread ViewNo JavascriptNo JS + Preview  Per page102550   
 Msgs 1 to 25 of 111 (Total in Forum: 111) (Refresh)FirstPrevNext
GeneralHow to integrate .NET Dll of QR Code with VB6 Pinmembersathyamvasu21:18 17 Nov '10  
Hi ,
I want to integrate .NET DLL (QR Code) with vb6,
please send guide to integrate with vb6

please in advance

Thank you
SathyaMoorthy
Sign In·View Thread·PermaLink2.00/5 (1 vote)
GeneralDecode incorrectly when encode with unicode string PinmemberThanh Hoang23:22 3 Nov '10  
Hi everyone,
I am from Viet Nam. This library decode incorrectly when I use unicode string like "Lê Thanh Hoàng" for encoding. How can I fix this issue?

Thanks in advanced!
Hoang Le
Sign In·View Thread·PermaLink1.00/5 (1 vote)
GeneralRe: Decode incorrectly when encode with unicode string PinmemberPiotr Czekalski4:02 28 Nov '10  
Same problem here with polish language.
I'm using BeeTagg to decode and it works only for some special characters but not all - this way I think the problem is not a decoding but encoding as well.

I've debugged and the source text to encode is correctly recognized as Unicode but doesn't work anyway.

Any help would be appreciated.

Regards,

Piotr
Sign In·View Thread·PermaLink 
GeneralIndexOutOfRangeException on Encode PinmemberSergio_791:24 22 Oct '10  
I have the same problem already here posted and it still seems there isn't a solution for this issue.

Anyone can give me some suggestions?

Any suggestion would be greatly appreciated..
Sign In·View Thread·PermaLink2.00/5 (1 vote)
GeneralIndexOutOfRangeException PinmemberSuperman10010:00 14 Oct '10  
i have IndexOutOfRangeException in QRCodeEncoder at

l2 = (max - 1) / 8 + 1;
sbyte[] codewords = new sbyte[maxDataCodewords];
for (int i = 0; i < l2; i++)
{
codewords[i] = 0; //<<-- here
}

when i try to encode a string format as this:

String 1\nString 2\nString 3

How to fix it?
Sign In·View Thread·PermaLink 
GeneralRe: IndexOutOfRangeException PinmemberOmar Del Toro M.12:07 14 Oct '10  
I was on the same issue than you, and then I used the dll inside Release folder under SampleApp.
Hope this helps.

Regards!
Sign In·View Thread·PermaLink 
AnswerRe: IndexOutOfRangeException Pinmemberpferril9:17 2 Nov '10  
Try to increase the QRCodeVersion of the Encoder, goes from 1 to 40 ( in theory ) http://www.denso-wave.com/qrcode/vertable1-e.html[^]
Sign In·View Thread·PermaLink 
GeneralRe: IndexOutOfRangeException Pinmemberdreamer_zl21:14 23 Nov '10  
There must be a bug in library, because when I set version by length, sometimes I get this error. Yes, increasing version is solution, but really not clean.
I have to catch IndexOutOfRangeException, then increase version and try to generate QR code again.

I set version by this table:
http://www.denso-wave.com/qrcode/vertable2-e.html[^]

Does anybody have expression to calculate max string length for version?
Sign In·View Thread·PermaLink 
GeneralRe: IndexOutOfRangeException Pinmembermmilos2:05 25 Nov '10  
Does anyone fixed this problem?
Sign In·View Thread·PermaLink 
GeneralMy vote of 5 PinmemberLeontti17:19 6 Oct '10  
Excelent implementation
Sign In·View Thread·PermaLink 
GeneralAnyone else having problems with lower case text encoding with this library PinmemberGuy Swartwood9:18 4 Oct '10  
I am using VS2010 on XP (w/ Framework 4). WHen I encode a mixed case text data like "Red Rover", I get an image when decoded says "R00 R0000". If I encode "RED ROVER", then the image I decode says "RED ROVER"

I have tried it with various versions (3 - 7), sizes and error correction.

Any suggestions why?
Sign In·View Thread·PermaLink5.00/5 (1 vote)
GeneralRe: Anyone else having problems with lower case text encoding with this library PinmemberSuperman10010:56 6 Oct '10  
i got the same problem!
i think the problem is in the encode engine because the qrcodes made with this:
http://www.qurify.com/ are correctly read.
Sign In·View Thread·PermaLink 
GeneralRe: Anyone else having problems with lower case text encoding with this library PinmemberGuy Swartwood5:03 6 Oct '10  
I did find that if you use the Byte encoding instead of AlphaNumeric, you get the result you are looking for. You are correct that it is in the coding engine because I found where in the source code it is ignoring lower-case when using alpha-numeric encoding.

Does anyone know if that is because of the QR spec?

I did find out that www.qurify.com[^] is automatically encoding the contents as byte instead of alphanumeric.
Sign In·View Thread·PermaLink 
General当version为30以上时,解码报错? Pinmemberjason_fang21:02 25 Sep '10  
当version为30以上时,解码报错:invalid version -24等
Sign In·View Thread·PermaLink 
GeneralMy vote of 5 Pinmemberexergonic16:32 20 Sep '10  
awesome! and beautiful baby, too.
Sign In·View Thread·PermaLink 
GeneralMy vote of 4 PinmemberNat Davies6:15 12 Sep '10  
not enough detail on the decoding.
Sign In·View Thread·PermaLink 
GeneralIf I want to add an other textbox, How should I do ?? Pinmemberharkkwon21:59 5 Sep '10  
In the program there is a textbox the name called txtEncodeData...
If I want add an other textbox How Should I do??
Sign In·View Thread·PermaLink1.00/5 (4 votes)
QuestionQR Code library called by a VB6 application Pinmembermbarbaglia12:58 26 Aug '10  
Hi, how can I integrate the QRCode library in a vb6 application?

I tried but the image of the QR code resulting isn't correct (there aren't any little squares inside of it).

Thanks!Confused
Sign In·View Thread·PermaLink1.50/5 (6 votes)
GeneralMy vote of 5 Pinmemberasingc15:20 20 Jul '10  
This is an effective project that made the use of QR code really easy. Minor fixes needed, but still tremendously helpful and significantly lowered the bar of further innovation. The author deserve huge credit.
Sign In·View Thread·PermaLink2.50/5 (2 votes)
GeneralHookup to webcam Pinmemberzeek3:37 7 Jul '10  
Any ideas to hook the decoder to a webcam ?

Excellent article.
Sign In·View Thread·PermaLink 
AnswerRe: Hookup to webcam Pinmembereijun8:39 15 Jul '10  
Hi,

I have not tried yet, but how about using this?

http://directshownet.sourceforge.net/[^]

Capture image with DirectShow.NET, and pass it to the decoder of QRCode Library.
Sign In·View Thread·PermaLink 
GeneralRe: Hookup to webcam Pinmembervrushikesh5:07 16 Jul '10  
Hi,

I have tried to Integrate QRCode with Live Video Utility from DirectShow, but I am getting following Exceptions

First Try,
string decodedString = decoder.decode(new QRCodeBitmapImage(new Bitmap(image)));

I got this excpetion
"This method must be called after QRCodeImageReader.getQRCodeSymbol() called"

Then I did Second Try

sbyte[] decodedString = decoder.decodeBytes(new QRCodeBitmapImage(new Bitmap(image)));

I got this excpetion
"Invalid number of Finder Pattern detected"

"Give up Decoding"
Yogesh Gurav

Sign In·View Thread·PermaLink1.50/5 (4 votes)
GeneralRe: Hookup to webcam PinmemberChubby Tomato22:26 4 Nov '10  
I got same exceptions when I use emguCV library to capture image from webcam.
Sign In·View Thread·PermaLink 
GeneralMy vote of 5 Pinmemberbluescorpio110718:17 6 Jul '10  
excellent
Sign In·View Thread·PermaLink 
NewsAwesome! Pinmemberben@kbvcorp.com9:29 1 Jul '10  
This was just what I needed. Examples and all!
Sign In·View Thread·PermaLink 
Last Visit: 20:20 15 Dec '10     Last Update: 20:45 15 Dec '10 12345 Next »

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+PgUp/PgDown to switch pages.

PermaLink | Privacy | Terms of Use
Last Updated: 20 Sep 2007

Copyright 2007 by twit88
Everything else Copyright © CodeProject, 1999-2010
Web23 | Advertise on the Code Project

转载于:https://www.cnblogs.com/417258821/archive/2010/12/16/1908213.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值