-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
How to use QRCoder
- Introduction
-
Installation
2.1. Via NuGet Package Manager
2.2. Latest/Nightly Builds
2.3. Development and sourcecode - Basic usage
- Advanced usage
As described on the wiki's home page the usage of QRCoder is really easy. To produce a QR Code you need only some lines of code. But if you want, you can parametrize nearly every thing. So this part of the wiki is split into simple- and advanced usage. For a quick start just read the next two paragraphs. If you want to go in detail, just have a look at the advanced usage examples.
For common usage just install QRCoder via NuGet. You can do this either via the graphical NuGet package manager in Visiual Studio or by using the following command in the NuGet Package Manager console:
PM> Install-Package QRCoder
If you're living on the edge and want to use the really latest release, you can use the development NuGet feeds which are available under the following urls:
NuGet V3 feed URL (Visual Studio 2015+): https://www.myget.org/F/qrcoder/api/v3/index.json
NuGet V2 feed URL (Visual Studio 2012+): https://www.myget.org/F/qrcoder/api/v2
If you want to have a look into the source or develop a new feature, just fork the repository or download the source code from the repository's main page.
After successful installtion of the QRCoder binary you can create your first QRCode with just a few lines of code. First import QRCoder via using-statement.
using QRCoder;
Then create an instance of the QRCodeGenerator-class and call the CreateQrCode-method with the payload (text) you want to encode into the QR Code.
CodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("The payload aka the text which should be encoded.", QRCodeGenerator.ECCLevel.Q);
Now you have the nearly ready to use QR Code inside the qrCodeData-variable. Now let's choose a "renderer", a Class which helps to represent this QR Code data as Graphic.
QRCode qrCode = new QRCode(qrCodeData);
Bitmap qrCodeImage = qrCode.GetGraphic(20);
And that's it! now you have a Bitmap-object called "qrCodeImage" which can be saved to disk, printed, shown on an application form, etc.
You may have wondered about the QRCodeGenerator.ECCLevel.Q-parameter in the CreateQrCode-function call. So let's talk about the parameters of this function. The CreateQrCode-function has four parameters whereby two are mandatory and two are optional.
Parameter name | Type | Default | Description |
---|---|---|---|
plainText | string | The text which shall be encoded in the QR Code. Write whatever you want. Use PayloadGenerater-class to make the QR Code "special" | |
eccLevel | QRCodeGenerator.ECCLevel | The error correction level. Either L (7%), M (15%), Q (25%) or H (30%). Tells how much of the QR Code can get corrupted before the code isn't readable any longer. | |
forceUtf8 | bool | false | This parameter enables you to force text encoding in UTF-8. Be default (and as required by QR code ISO/IEC standard) text in Byte mode will be encoded in ISO-8859-1. Only if chars are detected, which can't be encoded in ISO-8859-1, QRCoder will switch to UTF-8. |
utf8BOM | bool | false | This parameter enables you to set ByteOrderMark (BOM) when QRCoder uses UTF-8 for text-encoding. |
That is everything you have to know, when creating simple QR Codes. If you want more special code, have a look at the next paragraph regarding the "advanced usage".
Now, since you know the basic usage, let's have a look at the advanced "skills" of the QRCoder library. For further reading we divide these into two categories:
- Advanced usage: Different output formats / the renderers
- Advanced usage: How to write your own QR Code renderer (coming soon)
- Advanced usage: The PayloadGenerator-class
- Advanced usage: How to add new payload generators (coming soon)
Choose one of the links above to become a QRCoder expert! And don't forget - we appreciate your feedback.
Crafted with ❤ by Raffael Herrmann and a bunch of cool guys.