You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
2. Installation
2.1 Via NuGet Package Manager
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
2.2 Latest/Nightly Builds
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.)
2.3 Development and sourcecode
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.
3. Basic usage
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.
QRCodeGeneratorqrGenerator=newQRCodeGenerator();QRCodeDataqrCodeData=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.
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.
Parameters of the CreateQrCode method
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".
4. 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: