Skip to content

How to use QrSharp

Silas edited this page Jul 18, 2023 · 2 revisions

Introduction

As described on the wiki's home page the usage of QrSharp is really easy. To produce a QR Code you need only some lines of code. But if you want, you can parametrize nearly everything. So this part of the wiki is split into basic- and advanced usage.

Installation

Via NuGet Package Manager

For common usage just install QrSharp 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 QrSharp

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.

Basic usage

After successful installtion of the QrSharp binary you can create your first QR Code with just a few lines of code. First import QrSharp via using-statement.

using QrSharp;

Then call the CreateQrCode-method in the QRCodeGenerator class with the payload (text) you want to encode into the QR Code.

QrCodeData qrCodeData = QrCodeGenerator.CreateQrCode("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);
SKBitmap qrCodeImage = qrCode.GetGraphic(20);

And that's it! now you have a SKBitmap-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, QrSharp will switch to UTF-8.
utf8BOM bool false This parameter enables you to set ByteOrderMark (BOM) when QrSharp 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 QrSharp 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".

Advanced usage

Coming Soon

Clone this wiki locally