QrSharp 0.1.3

dotnet add package QrSharp --version 0.1.3                
NuGet\Install-Package QrSharp -Version 0.1.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="QrSharp" Version="0.1.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add QrSharp --version 0.1.3                
#r "nuget: QrSharp, 0.1.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install QrSharp as a Cake Addin
#addin nuget:?package=QrSharp&version=0.1.3

// Install QrSharp as a Cake Tool
#tool nuget:?package=QrSharp&version=0.1.3                

QrSharp

Info

QrSharp is a simple library, written in C#.NET, based on QRCoder which enables you to create QR codes. 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.

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

Feel free to grab-up/fork the project and make it better! As I did quite a lot of refactorings, I would much appreciate testing and opinions about the Project. Feel free to report any issues you find.

For more information see: Coming Soon

Release Notes

Coming Soon

QrSharp is a project by Silas Zahner the core of this project is QRCoder by Raffael Herrmann (big shoutout to him). It's licensed under the MIT license.


Installation

Either checkout this Github repository or install QrSharp via NuGet Package Manager. If you want to use NuGet just search for "QrSharp" or run the following command in the NuGet Package Manager console:

PM> Install-Package QrSharp

Usage

You only need four lines of code, to generate and view your first QR code.

QrCodeData qrCodeData = QrCodeGenerator.CreateQrCode("The text which should be encoded.", QrCodeGenerator.ECCLevel.Q);
QrCode qrCode = new QrCode(qrCodeData);
SKBitmap qrCodeImage = qrCode.GetGraphic(20);

Optional parameters and overloads

The GetGraphics-method has some more overloads. The first two enable you to set the color of the QR code graphic. One uses Color-class-types, the other HTML hex color notation.

//Set color by using Color-class types
SKBitmap qrCodeImage = qrCode.GetGraphic(20, Color.DarkRed, Color.PaleGreen, true);

//Set color by using HTML hex color notation
SKBitmap qrCodeImage = qrCode.GetGraphic(20, "#000ff0", "#0ff000");

The other overload enables you to render a logo/image in the center of the QR code.

FileStream logoStream = File.OpenRead("C:\\myimage.png");
SKBitmap logoBitmap = SKBitmap.Decode(logoStream);
SKBitmap qrCodeImage = qrCode.GetGraphic(10, SKColors.Black, SKColors.White, logoBitmap);

There are a plenty of other options. So feel free to read more on that in our wiki: Coming Soon

Special rendering types

Besides the normal QRCode class (which is shown in the example above) for creating QR codes in Bitmap format, there are some more QR code rendering classes, each for another special purpose.

  • QRCode
  • ArtQRCode
  • AsciiQRCode
  • Base64QRCode
  • BitmapByteQRCode
  • PdfByteQRCode
  • PngByteQRCode
  • PostscriptQRCode
  • SvgQRCode

For more information about the different rendering types click on one of the types in the list above or have a look at: Coming Soon

PayloadGenerator.cs - Generate QR code payloads

Technically QR code is just a visual representation of a text/string. Nevertheless most QR code readers can read "special" QR codes which trigger different actions.

For example: WiFi-QRcodes which, when scanned by smartphone, let the smartphone join an access point automatically.

This "special" QR codes are generated by using special structured payload string, when generating the QR code. The PayloadGenerator.cs class helps you to generate this payload strings. To generate a WiFi payload for example, you need just this one line of code:

PayloadGenerator.WiFi wifiPayload = new PayloadGenerator.WiFi("MyWiFi-SSID", "MyWiFi-Pass", PayloadGenerator.WiFi.Authentication.WPA);

To generate a QR code from this payload, just call the "ToString()"-method and pass it to the QrCodeGenerator.

//[...]
QRCodeData qrCodeData = QrCodeGenerator.CreateQrCode(wifiPayload.ToString(), QRCodeGenerator.ECCLevel.Q);
//[...]

You can also use overloaded method that accepts Payload as parameter. Payload generator can have QR Code Version set (default is auto set), ECC Level (default is M) and ECI mode (default is automatic detection).

//[...]
QRCodeData qrCodeData = QrCodeGenerator.CreateQrCode(wifiPayload);
//[...]

Or if you want to override ECC Level set by Payload generator, you can use overloaded method, that allows setting ECC Level.

//[...]
QRCodeData qrCodeData = QrCodeGenerator.CreateQrCode(wifiPayload, QRCodeGenerator.ECCLevel.Q);
//[...]

You can learn more about the payload generator in our wiki: Coming Soon

The PayloadGenerator supports the following types of payloads:

  • BezahlCode
  • Bitcoin-Like cryptocurrency (Bitcoin, Bitcoin Cash, Litecoin) payment address
  • Bookmark
  • Calendar events (iCal/vEvent)
  • ContactData (MeCard/vCard)
  • Geolocation
  • Girocode
  • Mail
  • MMS
  • Monero address/payment
  • One-Time-Password
  • Phonenumber
  • RussiaPaymentOrder (ГОСТ Р 56042-2014)
  • Shadowsocks configuration
  • Skype call
  • SlovenianUpnQr
  • SMS
  • SwissQrCode (ISO-20022)
  • URL
  • WhatsAppMessage
  • WiFi
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.3 327 7/3/2024
0.1.2 2,592 7/18/2023
0.1.1 138 7/18/2023
0.1.0 144 7/18/2023