• Stars
    star
    174
  • Rank 218,042 (Top 5 %)
  • Language
    C#
  • License
    MIT License
  • Created over 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Qr Code Generator with Skia. (no System.Drawing)

lint build debug

License: MIT NuGet

Skia.QrCode

Qr Code generator with Skia.Sharp.

Install

.NET CLI

$ dotnet add package SkiaSharp.QrCode

Package Manager

PM> Install-Package SkiaSharp.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;

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;

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);

TIPS

Linux support

You have 2 choice to run on Linux. If you don't need font operation, use SkiaSharp.NativeAssets.Linux.NoDependencies.

  1. Use SkiaSharp.NativeAssets.Linux package. In this case, you need to install libfontconfig1 via apt or others.
  2. Use SkiaSharp.NativeAssets.Linux.NoDependencies 2.80.2 or above. In this case, you don't need libfontconfig1.

SkiaSharp.NativeAssets.Linux.NoDependencies still can draw text, however can't search font cased on character or other fonts.

Detail: mono/SkiaSharp#964 (comment)

SkiaSharp.NativeAssets.Linux sample

sudo apt update && apt install -y libfontconfig1
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="SkiaSharp.QrCode" Version="0.5.0" />
    <PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.80.2" />
  </ItemGroup>
</Project>

SkiaSharp.NativeAssets.Linux.NoDependencies sample

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="SkiaSharp.QrCode" Version="0.5.0" />
    <PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.2" />
  </ItemGroup>
</Project>

Docker Build & Run

Test Build lib.

docker build -t skiasharp.qrcode .

Test Run on linux.

cd samples/LinuxRunSamples
docker-compose up

License

MIT

Thanks

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

More Repositories

1

PowerShellUtil

PowerShell Common Utilities
PowerShell
147
star
2

AzureFunctionsIntroduction

Sample Code for Azure Functions
C#
90
star
3

valentia

PowerShell Remote deployment library for Windows Servers
PowerShell
54
star
4

GraniResource

PowerShell Desired State Configuration Resources for real production workload.
PowerShell
42
star
5

githubactions-lab

github actions ci lab
C#
41
star
6

ScoopPlaybook

Define Scoop as YAML and run single command.
PowerShell
22
star
7

UnityBuildRunner

Wrapper cli tool which output Unity batch build log to StandardOutput.
C#
21
star
8

git-shallow-clone-orb

circleci orb to execute git shallow clone for faster checkout.
21
star
9

local-provisioner

local development env provisioner for Ubuntu, Raspi, macOS and Windows.
Shell
16
star
10

UnityCloudbuildApi

C# Client for Unity Cloud Build API
C#
14
star
11

WindowsCredentialVault

Windows 8 Store App style Windows Credential Management Module for Windows PowerShell
PowerShell
11
star
12

S3Sync

Amazon S3 Content Synchronization with .NET
C#
11
star
13

WinCredManager

PowerShell Credential Store wrapper to use Windows Credential Manager
PowerShell
10
star
14

CsProjEditor

csproj editor
C#
9
star
15

docker-jmeter-gui

JMeter GUI Alpine image connectable with RDP or VNC
Dockerfile
8
star
16

DSCSample

DSC Sample for Windows PowerShell
PowerShell
7
star
17

AWSLambdaCSharpIntroduction

Introduction and samples for AWS Lambda with C# (.NET Core)
C#
5
star
18

dotnet-lab

Often use phrases in C# and dotnet related.
C#
4
star
19

AgonesPod

In Pod Kubernetes client to access Agones Controller API from .NET
C#
4
star
20

Base64UrlCore

CLI tool for base64 & base64url encode/decode for URL applications.
C#
3
star
21

PS-Linux

Linux Command alter by PowerShell
PowerShell
3
star
22

MagicOnion-lab

MagicOnion lab
ShaderLab
3
star
23

benchmark-grpc-lab

C#
2
star
24

scoop-bucket

A bucket for scoop.
PowerShell
2
star
25

FirebaseSampleCloudFunctions

TypeScript
2
star
26

math-lab

Implementation of some math algorithms
C#
2
star
27

GitContinuousPull

Automated Clone -> Pull -> PostAction Module
PowerShell
2
star
28

MyOneGetServer

Sample for Custom OneGet Server with NuGet Server
PowerShell
2
star
29

OpenUserSecrets

Visual Studio Extensions for UserSecrets on .NET Core Console
C#
2
star
30

PS-WaybackMachineAvailavility

PowerShell function to obtain Wayback Machine Availavility from Wayback Machine APIs
PowerShell
2
star
31

csharp-lab

C# lab
C#
2
star
32

dotfiles-win

dot files for windows
PowerShell
2
star
33

UnityMetaInjection

Unity YAML file Injection.
C#
2
star
34

PSSumoLogicAPI

PowerShell SumoLogic API Management Module
PowerShell
2
star
35

docker-atlantis-ansible

docker for atlantis with ansible
Dockerfile
2
star
36

Book-PowerShell-Samples

PowerShell ๅฎŸ่ทตใ‚ฌใ‚คใƒ‰ใƒ–ใƒƒใ‚ฏใฎใ‚ตใƒณใƒ—ใƒซใ‚นใ‚ฏใƒชใƒ—ใƒˆ
PowerShell
2
star
37

DSCResources

WARNING THIS REPO IS DEPRECATED!! ALL SOURCES ARE MOVED TO GraniResource.
PowerShell
2
star
38

docker-lab

docker labo
C#
1
star
39

NancySelfHost

TopShelf + OWIN + Nancy Selfhost Sample project
C#
1
star
40

WebPlatformInstaller

WebPlatformInstaller Module will manage your installation through WebPI.
PowerShell
1
star
41

WpfAppLinuxBuild

WpfApp build on Linux from .NET7
C#
1
star
42

envoy-lab

envoy lab
Go
1
star
43

AgonesSample

Agones Sample Server and Client
C#
1
star
44

AgonesSdkCsharp

.NET Core Agones SDK for Agones Managed pod
C#
1
star
45

MixedContentChecker

Check https MixedContent via sitemap.xml
C#
1
star
46

SwapTasks

MSBuild Task to provide SwapFile and clean up folder on publish.
C#
1
star
47

kubernetes-lab

kubernetes lab
C#
1
star
48

dotfiles-linux

dot files for Ubuntu and WSL Ubuntu
Shell
1
star
49

guitarrapc.github.io

My Resume. Circle CI + Github Pages Hostring
HTML
1
star
50

UnityTutorial

Ref: http://tutorial.unity3d.jp/ && https://github.com/unity3d-jp/FirstTutorial/wiki
C#
1
star
51

jenkins-pipeline-lab

Groovy
1
star
52

UniRx.ReferenceSource

Reference Source for UniRx
HTML
1
star
53

nativebuild-lab

Native Build lab
C#
1
star
54

Utf8BomHeader

Utf8 Bom Header Handling Module for PowerShell
PowerShell
1
star
55

R.Unity

Get strong typed, autocompleted resources like images, fonts and scenes in Unity projects
C#
1
star
56

azuredevops-lab

Azure DevOps Lab
HTML
1
star
57

DayBreakJP

An experimental programming language built onto of PowerShell, using Japanese rather than English as its basis. Inspired by DayBreak-ChinesePowerShell https://github.com/klumsy/DayBreak-ChinesePowerShell
PowerShell
1
star