Skip to content
Qr Code Generator with Skia. (no System.Drawing)
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
sample
src/SkiaSharp.QrCode
.editorconfig
.gitignore
Dockerfile
LICENSE.md
README.md
SkiaSharp.QrCode.sln
appveyor.yml

README.md

CircleCI License: MIT

NuGet

Skia.QrCode

Qr Code generator with Skia.Sharp.

Install

.NET CLI

$ dotnet add package SkiaQrCode

Package Manager

PM> Install-Pacakge Skia.QrCode

Motivation

There are many System.Drawing samples to generate QRCode, and there are a lot of cases I want avoid System.Drawing for GDI+ issue. However, you may require many conding to generate QRCode using ZXing.Net or ImageSharp or Core.Compat.System.Drawing.

I just want to create QR in much simpler way.

Why Skia?

Performance and size and .NET Core support status.

.NET Core Image Processing

Sample Code

Here's minimum sample to generate specific qrcode via args.

using SkiaSharp;
using SkiaSharp.QrCode.Image;
using System;
using System.IO;

namespace SimpleGenerate
{
    class Program
    {
        static void Main(string[] args)
        {
            var content = "testtesttest";
            using (var output = new FileStream(@"output/hoge.png", FileMode.OpenOrCreate))
            {
                // generate QRCode
                var qrCode = new QrCode(content, new Vector2Slim(256, 256), SKEncodedImageFormat.Png);

                // output to file
                qrCode.GenerateImage(output);
            }
        }
    }
}

If you want specify detail, you can generate manually.

using SkiaQrCode;
using SkiaSharp;
using System;
using System.IO;

namespace SkiaQrCodeSampleConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            var content = "testtesttest";
            using (var generator = new QRCodeGenerator())
            {
                // Generate QrCode
                var qr = generator.CreateQrCode(content, ECCLevel.L);

                // Render to canvas
                var info = new SKImageInfo(512, 512);
                using (var surface = SKSurface.Create(info))
                {
                    var canvas = surface.Canvas;
                    canvas.Render(qr, info.Width, info.Height);

                    // Output to Stream -> File
                    using (var image = surface.Snapshot())
                    using (var data = image.Encode(SKEncodedImageFormat.Png, 100))
                    using (var stream = File.OpenWrite(@"output/hoge.png"))
                    {
                        data.SaveTo(stream);
                    }
                }
            }
        }
    }
}

Build

docker build -t skiasharp.qrcode .

License

MIT

Thanks

aloisdeniel/Xam.Forms.QRCode : Qr Sample with Skia codebude/QRCoder : all QRCode generation algorithms

You can’t perform that action at this time.