Coder Social home page Coder Social logo

superstreber3 / qrsharp Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 3.0 261 KB

QrSharp is a simple library built on the foundations of QRCoder, written in C#.NET, which enables you to create QR codes.

License: MIT License

C# 100.00%
barcode c-sharp csharp girocode girocode-generator qrcode qrcode-generator swissqrcode qrsharp

qrsharp's Introduction

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

Legal information and credits

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

qrsharp's People

Contributors

silaszahner avatar superstreber3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

qrsharp's Issues

switching from qrcoder to qrsharp unable to display qrcode from base64

Describe the bug
OTP QRCode from Base64 Uri won't be displayed properly.

To Reproduce
Steps to reproduce the behavior:

ASP.NET WebApp Razor Page
.cshtml.cs

		public async Task<IActionResult> OnPost()
		{
			QRCodeIMG = await GetQRTask()
			return Page();
		}
public async Task<string> GetQRTask()
{
			string url = $"otpauth://totp/randomname:randomuser?secret=RANDOMSECRET";
			QrCodeData qrCodeData = QrCodeGenerator.CreateQrCode(url, QrCodeGenerator.ECCLevel.Q);
			BitmapByteQrCode qrCode = new(qrCodeData);
			byte[] qrCodeAsBitmapByteArr = qrCode.GetGraphic(10, SKColors.DarkGray.ToString(), SKColors.Orange.ToString());
			QRCodeImg = "data:image/png;base64," + Convert.ToBase64String(qrCodeAsBitmapByteArr);
			return QRCodeImg;
}

.cshtml

<img id="UserQR" src="@Model.QRCodeImg" alt="QRCodeImg"/>

Expected behavior

DIsplaying a QRCode

Screenshots

Download

Environment

  • OS: Windows & Linux
  • .net version 6.0
  • QrSharp version latest

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.