Skip to content
Silas edited this page Jul 18, 2023 · 2 revisions

What is QrSharp

QrSharp is a .NET library, completely written in C#, based on the QRCoder by Raffael Herrmann which enables you to generate QR Codes as defined by ISO/IEC 18004. The main target of the QrSharp library is to deliver a small and easy to use solution. (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, QrSharp is really flexible - in both "output formats" as well as in "payload types". Payload types? Yes, QrSharp 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

How to use QrSharp

What can and can't QrSharp do for you?

To put it in a nutshell - QrSharp 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 QrSharp suits your needs. But if you want to create a QR Code reader, than you should use another library.

On which systems is QrSharp available?

As System.Drawing is since .net6.0 windows only, I've decided to create a fork of the original project and use SkiaSharp instead. This is the recommended way to handle graphics in .net6.0 and above.

QrSharp only support .net6.0 and above. If you need support for older versions of .net, please use the original project.

How does QrSharp's architecture look like?

To understand QrSharp'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 QrSharp's architecture?

In QrSharp we separated the data (and QR Code generator) logic from the represenation logic.

QrCodeData qrCodeData = QrCodeGenerator.CreateQrCode("The text which should be encoded.", QrCodeGenerator.ECCLevel.Q);

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 SkBitmap object which can be encoded adn then saved as .bmp, .jpg, .png, .gif, ...)
  • ArtQRCode (Returns a SkBitmap 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.)
  • 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.)
  • 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)

What makes QrSharp special?

  • Easy and compact solution
  • Multiple output formats (see the paragraph about renderers above)
  • Massive payload generator which support a lot of special payload types
  • Full Support for modern Vesions of .net