-
-
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
The NuGet.org feed contains only major/stable releases. If you want the latest functions and features, you can use the CI builds via Github packages. (More information on how to use Github Packages in Nuget Package Manager can be found here.)
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.
QRCodeGenerator 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 six parameters whereby two are mandatory and four 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. |
eciMode | EciMode | EciMode.Default | This parameter allows you to specify a fixed EciMode. Possible values are: EciMode.Default, EciMode.Iso8859_1, EciMode.Iso8859_2, EciMode.Utf8. Use this only if you really need to. Otherwise keep the value default. |
requestedVersion | int | -1 | If set other than default (= -1), it will set a fixed QR code version. When doing so, keep in mind to choose a version that has enough space to save your payload. Otherwise use -1 and QRCoder will automatically choose the right version. |
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: QR Code raw data export
- Advanced usage: How to write your own QR Code renderer (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.