-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Home
-
What is QRCoder?
1.1. How to use QRCoder? - What can and can't QRCoder do for you?
- On which systems is QRCoder available?
- How does QRCoder's architecture look?
- What makes QRCoder special?
QRCoder is a .NET library, completely written in C#, which enables you to generate QR Codes as defined by ISO/IEC 18004. The main target of the QRCoder library is to deliver a small and easy to use solution, which has no dependencies to other libraries or network stacks. (Like QR Code generators which are relying on online services which makes them vulnerable/slow in some cases.)
Although simplicity is one of the main goals, QRCoder is really flexible - in both "output formats" as well as in "payload types". Payload types? Yes, QRCoder brings its own "payload generator", which helps you to create a big list of different payload types to generate special QR codes like "WiFi QR Codes", "Girocodes", "SwissQRCodes" and many more (see full list of payload generators).
If you are not interested in general-/background information, but want to start coding right now, then have a look at our "How to"-Page.
To put it in a nutshell - QRCoder can generate QR Codes but it can't read them. Its strength lays in the generation of QR Codes in many different ways. So if you want to show QR Codes in your mobile app or business application, print them on invoices, show them on your website, ... then QR Coder suits your needs. But if you want to create a QR Code reader, than you should use another library.
Since QRCoder is written in C#.NET it runs - in the first place - on every platform which supports the .NET-Framework/.NET Core/.NET The Nuget-Package contains different versions (.NET 3.5, .NET 4.0, .NET 5.0, .NET 6.0 and .NET Standard/Core) binaries, so that it supports multiple platforms.
Unfortunately we have to admit, that it comes to some constraints when using the .NET Standard/.NET >=5.0 (non-Windows) versions. Since these library versions have to run on a bunch of different systems and OS and not every of this systems/OS supports the full System.Drawing stack, we had to remove some of the QRCoder renderer types. But if you keep this in mind, this won't stop you to get the same results as in the full version. (You only have to write some more lines of platform dependent code.)
As of now we know from projects in C# Winforms/WPF/WinUI3, ASP.NET, Blazor, Mono on Linux, .NET Core on Ubuntu, Unity on Android and Microsoft Office VBA and more which use QRCoder for their QR Code generation.
To understand QRCoder's architecture we have to look at the structure of QR Codes at first. A QR Code is a code which consists of black and white blocks, the so called "modules". The modules represent the data (=payload), which was encoded into the QR Code, as also some additional information about QR Code version, format, etc. So what has this todo with QRCoder's architecture?
In QRCoder we separated the data (and QR Code generator) logic from the represenation logic.
using var qrGenerator = new QRCodeGenerator();
using var qrCodeData = qrGenerator.CreateQrCode("My payload to be encoded.");
The example above represents the data logic. By calling the CreateQrCode
-method the payload will be encoded as QR Code and returned to the QRCodeData
-object named qrCodeData
. This data object contains the information about all the modules - e.g. first row, first column = black, first row, second column = white, ... and so on.
Now you could write your own renderer to make an image out of this information. This gives you 100% flexibility. You want circles instead of squares? Draw the information as circles. You want the modules to be opaque? Draw ...
If you don't like flexibility or just want to get fast results, don't panic. For this case we implemented the representation logic, which is a set of different classes (also called renderers) which take the QrCodeData
and output the QR Code in your favourite file format.
At the moment the following renderers are implemented:
-
QRCode
(Returns a Bitmap object which can be saved as .bmp, .jpg, .png, .gif, ...) -
ArtQRCode
(Returns a Bitmap object same as QRCode, but allows to render QR Codes with a more "artistic" style. You can set background images and define how the module are rendered. (As default they will be rendered as dots/circular).) -
AsciiQRCode
(Returns a string or string[] which contains the QR code as "ASCII art", built just out of ASCII chars.) -
Base64QRCode
(Returns the QR Code as Base64 image which can be embedded in websites, etc.) -
BitmapByteQRCode
(Returns a Byte-Array which contains a Bitmap. This works as best on platforms which don't support System.Drawing) -
PdfByteQRCode
(Returns the a byte-array which contains a PDF document that contains the QR Code.) -
PngByteQRCode
(Returns a Byte-Array which contains a PNG image. This works as best on platforms which don't support System.Drawing) -
PostscriptQRCode
(Returns a string in Postscript format that can be send to printers.) -
SvgQRCode
(Returns a String which contains the QR Code as SVG vector graphic) -
UnityQRCode
(Returns a Texture2D object for usage in Unity projects) -
XamlQRCode
(Returns a scalable vector XAML object tree to be used in XAML-based apps like WPF, Silverlight, ...)
You can find more information on the different renderers right here. We would be proud to see your renderer in this list, too. So feel free to write a new renderer and contribute it to this project.
Let us just list some points...
- Easy and compact solution
- Multi-platform (through different target frameworks: net35, net40, netstandard1.3, netstandard2.0, net5.0, net5.0-windows, net6.0, net6.0-windows - all included in the main NuGET package)
- Multiple output formats (see the paragraph about renderers above)
- Massive payload generator which support a lot of special payload types (for more information check this wiki page)
Crafted with ❤ by Raffael Herrmann and a bunch of cool guys.