SkiaSharp.QrCode 1.0.1
SkiaSharp.QrCode
SkiaSharp.QrCode provides high-performance QR code generation/read with SkiaSharp integration.

Benchmark results comparing SkiaSharp.QrCode with other libraries. See src/SkiaSharp.QrCode.Benchmark for details. Above results are generated on .NET 10 with AMD Ryzen 9 7950X3D CPU, with GFNI and AVX2 enabled.
Many existing QR code libraries rely on System.Drawing, which has well-known GDI+ limitations and cross-platform issues. SkiaSharp.QrCode was created to provide high performance, minimum memory allocation, a simpler and more intuitive API while leveraging SkiaSharp's cross-platform capabilities. Generate a QR code in a single line, or customize every detail - the choice is yours.
You can create professional-looking QR codes like this with just a few lines of code:
See samples/ConsoleApp for code examples generating these styles.
Playground
Try SkiaSharp.QrCode in your browser — no install required: SkiaSharp.QrCode Playground
The playground runs the actual library compiled to WebAssembly (GitHub Pages, fully static). Tune gradients, module shapes, finder patterns and logos in realtime, then download the PNG or SVG, or share your settings as a permalink. Every generated code is decoded back in-browser by the library's own decoder as a self-check, and the Decode an image panel reads QR codes from your own image files. Source lives in src/SkiaSharp.QrCode.Playground; it is deployed to GitHub Pages by release.yaml as part of every release.
Overview
SkiaSharp.QrCode is a modern, high-performance QR code generation library built on SkiaSharp. SkiaSharp.QrCode allocates memory only for the actual QR code data, with zero additional allocations during processing.
- Simple API: One-liner QR code generation with sensible defaults
- High Performance: Optimal speed and minimum memory allocation
- Highly Customizable: Gradients, icons, custom shapes, colors, and more
- Raster & Vector Output: PNG, JPEG, WebP, and SVG (scales without quality loss)
- Cross-Platform: Windows, Linux, macOS, iOS, Android, WebAssembly
- Zero Dependencies: QR generation without external libraries (SkiaSharp for rendering only)
- No System.Drawing: Avoids GDI+ issues and Windows dependencies
- NativeAOT Ready: Full support for .NET Native AOT compilation
- Modern .NET: .NET Standard 2.0, 2.1, .NET 8+
Installation
Visit SkiaSharp.QrCode on NuGet.org
dotnet add package SkiaSharp.QrCode
Quick Start
Simplest Example
Single line QR code generation:
using SkiaSharp.QrCode.Image;
// one-liner save to file
File.WriteAllBytes("qrcode.png", QRCodeImageBuilder.GetPngBytes("Hello"));
// Or get bytes
var pngBytes = QRCodeImageBuilder.GetPngBytes("https://example.com");
Common Use Cases
Generate QR Code for URL.
var pngBytes = QRCodeImageBuilder.GetPngBytes("https://example.com");
File.WriteAllBytes("qrcode.png", pngBytes);
WiFi QR Code.
var wifiString = "WIFI:T:WPA;S:MyNetwork;P:MyPassword;;";
File.WriteAllBytes("wifi-qr.png", QRCodeImageBuilder.GetPngBytes(wifiString));
SVG (vector) output.
File.WriteAllText("qrcode.svg", QRCodeImageBuilder.GetSvgString("https://example.com"));
Generate with Custom Settings.
var qrCode = new QRCodeImageBuilder("https://example.com")
.WithSize(512, 512)
.WithErrorCorrection(ECCLevel.H)
.ToByteArray();
Save Directly to Stream
using SkiaSharp.QrCode.Image;
using var stream = File.OpenWrite("qrcode.png");
QRCodeImageBuilder.SavePng("Your content here", stream, ECCLevel.M, size: 512);
Migration
See Migration Guide for details on migrating from older versions of SkiaSharp.QrCode.
API Overview
SkiaSharp.QrCode provides three main APIs for generation, plus QRCodeDecoder for decoding.
Recommendation: Start with QRCodeImageBuilder for most scenarios. Use QRCodeRenderer when you need canvas control. Use QRCodeGenerator only for custom rendering implementations. Use QRCodeDecoder to read QR codes back (round-trip validation, decoding rendered images).
| Feature | QRCodeImageBuilder | QRCodeRenderer | QRCodeGenerator |
|---|---|---|---|
| Ease of use | High | Medium | Low |
| Flexibility | Medium | High | Highest |
| Built-in rendering | Yes | Yes | No |
| Custom canvas control | No | Yes | N/A |
| Recommended for beginners | Yes | No | No |
QRCodeImageBuilder (Recommended)
Best for Most use cases - simple to advanced QR code generation. The high-level, fluent API for generating QR codes with minimal code. Provides a builder pattern with sensible defaults and extensive customization options.
Key Features:
- One-liner generation with
GetPngBytes(),SavePng(),SaveSvg() - Fluent API with
WithXxx()methods - Built-in support for colors, gradients, icons, shapes
- Multiple output formats (PNG, JPEG, WebP, SVG)
- Stream and byte array output
When to use:
- Quick QR code generation
- Standard customization needs
- File or stream output
Example:
var pngBytes = QRCodeImageBuilder.GetPngBytes("content");
QRCodeRenderer (Advanced)
Best for Custom rendering with full control over the canvas. The mid-level API that renders QR data onto an existing SkiaSharp canvas. Useful when you need to integrate QR codes into existing graphics or add custom post-processing.
Key Features:
- Render to existing
SKCanvas - Full control over rendering area (
SKRect) - Combine with other SkiaSharp drawing operations
- Custom effects and post-processing
When to use:
- Integrating QR codes into existing graphics
- Adding custom decorations or effects
- Multiple elements on the same canvas
Example:
var qrData = QRCodeGenerator.CreateQrCode("content", ECCLevel.M);
var canvas = surface.Canvas;
QRCodeRenderer.Render(canvas, area, qrData, SKColors.Black, SKColors.White);
QRCodeGenerator (Low-Level)
Best for QR data generation without rendering. The low-level API that generates raw QR code data (QRCodeData). Use this when you need the QR data structure itself, not the image.
Key Features:
- Generates
QRCodeData(boolean module matrix stored as 1D byte array) - Specify ECC level, ECI mode, quiet zone size
- No rendering logic included
- Smallest API surface
When to use:
- Custom rendering implementations
- Non-image output (e.g., ASCII art, LED displays)
- Maximum control over the rendering process
Example:
var qrData = QRCodeGenerator.CreateQrCode("content", ECCLevel.M, quietZoneSize: 4);
// Use qrData for custom rendering
// Access individual modules: bool isDark = qrData[row, col];
Zero-Allocation Generation (Span destination)
For high-throughput scenarios (e.g., per-request QR generation on a web server), you can generate the module matrix into a caller-provided buffer with zero heap allocation. Calculate the required size with GetRequiredBufferSize, allocate (or rent) the buffer yourself, and pass it as Span<byte>:
// 1. Calculate required buffer size (no allocation)
var calculated = QRCodeGenerator.GetRequiredBufferSize("content", ECCLevel.M, quietZoneSize: 4);
// 2. Allocate the buffer yourself (pool it, reuse it, or stackalloc it)
var buffer = ArrayPool<byte>.Shared.Rent(calculated.BufferSize);
try
{
// 3. Generate directly into the buffer; returns bytes written (= QrSize * QrSize)
var written = QRCodeGenerator.CreateQrCode("content", ECCLevel.M, buffer, quietZoneSize: 4);
// 4. Slice to the written region and consume
var matrix = buffer.AsSpan(0, written);
// One byte per module (0 = light, 1 = dark), row-major, quiet zone included:
var isDark = matrix[row * calculated.QrSize + col] != 0;
}
finally
{
ArrayPool<byte>.Shared.Return(buffer);
}
Buffer sizes are bounded: version 40 with the standard quiet zone needs 185 × 185 = 34,225 bytes, so a pooled or fixed buffer keeps memory usage constant regardless of request volume. The buffer region is cleared before writing, so dirty pooled buffers are fine; bytes beyond the written region are left untouched.
QRCodeDecoder (Decoding)
Decodes QR codes back into text — the inverse of QRCodeGenerator. Works at two levels:
- Matrix level: from
QRCodeDataor a byte-per-module span (the same format the zero-allocation generator produces). Full Reed-Solomon error correction included. - Image level: from
SKBitmapor a grayscale luminance span. Detects the QR code (arbitrary rotation, mirroring, inverted light-on-dark palettes and mild perspective supported), samples the grid, then decodes.
Scope: image decoding targets clean inputs — screenshots, rendered QR codes, and scans. Real-world photos with strong perspective, uneven lighting, or blur are out of scope; use a computer-vision grade reader such as ZXing.Net for those. See QR Code Decoder for design details.
// From QRCodeData (e.g. round-trip validation)
var qrData = QRCodeGenerator.CreateQrCode("content", ECCLevel.M);
if (QRCodeDecoder.TryDecode(qrData, out var text))
{
Console.WriteLine(text); // "content"
}
// From an image
using var bitmap = SKBitmap.Decode("qr.png");
if (QRCodeDecoder.TryDecode(bitmap, out var text, out var info))
{
Console.WriteLine($"{text} (version {info.Version}, ECC {info.EccLevel}, {info.ErrorsCorrected} errors corrected)");
}
// Zero-allocation: span in, span out
Span<char> destination = stackalloc char[QRCodeDecoder.GetMaxDecodedLength(version)];
if (QRCodeDecoder.TryDecode(moduleSpan, size, destination, out var written, out _))
{
var text = destination.Slice(0, written); // no heap allocation
}
On failure, QRCodeDecodeInfo.Status explains why (NotDetected, FormatInformationInvalid, DataUncorrectable, UnsupportedContent, ...). Supported content: Numeric / Alphanumeric / Byte modes, ISO-8859-1 and UTF-8 (with or without ECI), versions 1-40, all ECC levels. Kanji mode, FNC1 and Structured Append are detected and reported as unsupported rather than misdecoded.
Platform-Specific Considerations
Linux Support
SkiaSharp requires native dependencies on Linux. You have two options:
Option 1: With Font Support (Recommended for text rendering)
Requires libfontconfig1:
sudo apt update && apt install -y libfontconfig1
<PackageReference Include="SkiaSharp.QrCode" Version="0.9.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="3.119.1" />
Option 2: No Dependencies (QR code only)
If you don't need advanced font operations:
<PackageReference Include="SkiaSharp.QrCode" Version="0.9.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="3.119.1" />
Note:
NoDependenciescan still draw text but cannot search fonts based on characters or use system fonts.See: SkiaSharp Issue #964
NativeAOT Support
SkiaSharp.QrCode fully supports .NET NativeAOT. You need to include platform-specific native assets:
<PropertyGroup>
<PublishAot>true</PublishAot>
<PublishTrimmed>true</PublishTrimmed>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
Warning
When using PublishTrimmed, ensure that your QR code content and rendering logic doesn't rely on reflection or dynamic code that might be trimmed.
Windows
<PackageReference Include="SkiaSharp.QrCode" Version="0.9.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Win32" Version="3.119.1" />
Linux
<PackageReference Include="SkiaSharp.QrCode" Version="0.9.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="3.119.1" />
macOS
<PackageReference Include="SkiaSharp.QrCode" Version="0.9.0" />
<PackageReference Include="SkiaSharp.NativeAssets.macOS" Version="3.119.1" />
Performance
SkiaSharp.QrCode is designed with performance as a top priority. The library minimizes memory allocations and maximizes throughput for QR code generation.
Key Performance Characteristics
- Minimal Memory Allocation: Memory is only allocated for the final QR code data structure. The generation algorithm avoids intermediate allocations, resulting in minimal GC pressure.
- Zero-Copy Rendering: Direct rendering to SkiaSharp canvas without unnecessary buffer copies.
- Optimized Encoding: Efficient encoding mode selection and bit packing minimize QR code size and generation time.
- Native Performance: Leverages SkiaSharp's native rendering engine for maximum speed.
Benchmark Results
Benchmark results show SkiaSharp.QrCode outperforming other popular .NET QR code libraries in both speed and memory usage.
- Fastest Generation: Outperforms other .NET QR code libraries in most scenarios
- Lowest Memory Usage: Minimal allocations reduce GC overhead
- Consistent Performance: Predictable performance across different QR code sizes and complexity
For detailed benchmark code and results, see the samples/Benchmark directory.
FAQ
Why choose SkiaSharp.QrCode?
SkiaSharp offers several advantages for QR code generation:
- Performance: Native-level performance with hardware acceleration support
- Cross-Platform: Runs on Windows, Linux, macOS, iOS, Android, and WebAssembly
- Modern .NET Support: First-class support for .NET 6+ and .NET Core
- No GDI+ Dependencies: Avoids System.Drawing's Windows-specific issues
- Rich Graphics API: Advanced rendering capabilities (gradients, shapes, effects)
- Active Development: Well-maintained with regular updates
Can I use this in ASP.NET Core?
Yes, SkiaSharp.QrCode works great in ASP.NET Core. SkiaSharp.QrCode also supports IBufferWriter for efficient memory usage.
app.MapGet("/qr", (string url) =>
{
var pngBytes = QRCodeImageBuilder.GetPngBytes(url);
return Results.File(pngBytes, "image/png");
});
app.MapGet("/qr.svg", (string url) =>
{
var svgBytes = QRCodeImageBuilder.GetSvgBytes(url);
return Results.File(svgBytes, "image/svg+xml");
});
Does it support Blazor WebAssembly?
Yes, SkiaSharp.QrCode works in Blazor WebAssembly & Pure WebAssembly.
- See the samples/BlazorWasm folder for a Blazor WebAssembly example.
- See src/SkiaSharp.QrCode.Playground for Pure WebAssembly usage.
What about NativeAOT and trimming?
Yes, fully supported. See the Platform-Specific Considerations section for details on required native assets.
ISO-8859-2 and other encodings supports
Currently, SkiaSharp.QrCode supports ISO-8859-1 and UTF-8. Other encodings (e.g., ISO-8859-2, Shift JIS) are not supported at this time. This is mainly due to almost all QR code use cases being UTF-8 compatible nowadays. ISO-8859-2 and other legacy encodings are rarely used in practice.
| Supported | Encoding Mode | Encoding |
|---|---|---|
| Supported | Numeric | ISO-8859-1 |
| Supported | Alphanumeric | ISO-8859-1 |
| Supported | Byte | UTF-8 |
| Not Supported | Kanji | Shift-JIS |
Does SVG output require SkiaSharp.Svg or other packages?
No. SVG output uses SKSvgCanvas from the core SkiaSharp package — no additional dependencies. Note that SkiaSharp.QrCode outputs SVG only; it does not read or render existing SVG files.
Any plan to support QR code scanning?
Yes. QRCodeDecoder decodes QR codes from module matrices and from images (see API Overview). Image decoding intentionally targets clean inputs: screenshots, rendered QR codes, and scans, including rotated and mirrored ones. Robust decoding of real-world photos (perspective distortion, uneven lighting, blur) is a computer-vision problem outside this library's scope — use a dedicated reader such as ZXing.Net for camera captures.
What QR code style provides the best scan reliability?
For optimal scan reliability, we recommend:
- Use rectangular modules (default): Rectangle-shaped modules (
RectangleModuleShape) provide the lowest error rate when scanning QR codes. - Avoid gaps between modules: Using smaller module sizes or shapes like
CircleorRoundRectcreates gaps between modules, which increases scan error rates. - Use
ECCLevel.Hfor non-standard styles: If you need to useCircle,RoundRect, or other custom module shapes, we strongly recommend setting the error correction level toECCLevel.H(High - 30% recovery capacity) to compensate for the reduced readability. - Always use
ECCLevel.Hwith icons/logos: When embedding icons or logos usingIconData,ECCLevel.His required to ensure the QR code remains scannable even when the center is partially obscured.
Example:
// Best reliability - default settings with rectangular modules
var pngBytes = QRCodeImageBuilder.GetPngBytes("https://example.com");
// If using Circle or RoundRect - use High error correction
var qrCode = new QRCodeImageBuilder("https://example.com")
.WithSize(800, 800)
.WithErrorCorrection(ECCLevel.H) // Required for custom shapes
.WithModuleShape(CircleModuleShape.Default);
// When using icons/logos - always use High error correction
using var logo = SKBitmap.Decode(File.ReadAllBytes("logo.png"));
var icon = IconData.FromImage(logo, iconSizePercent: 15);
var qrCodeWithIcon = new QRCodeImageBuilder("https://example.com")
.WithSize(800, 800)
.WithErrorCorrection(ECCLevel.H) // Required for icons
.WithIcon(icon);
How can I display QR codes in LINQPad?
Following shows how to display a QRCode inside a LINQPad Results pane.
Bitmap.FromStream(new MemoryStream(QRCodeImageBuilder.GetPngBytes("WIFI:T:WPA;S:mynetwork;P:mypass;;"))).Dump();
QR code Specifications
ECC Level (Error Correction Levels)
QR codes support four levels of error correction, which allow the code to remain readable even when partially damaged or obscured:
| ECC Level | Error Correction Capability | Use Case |
|---|---|---|
| L (Low) | ~7% recovery | Clean environments, maximum data capacity |
| M (Medium) | ~15% recovery | General purpose (default recommended) |
| Q (Quartile) | ~25% recovery | Outdoor use, moderate damage expected |
| H (High) | ~30% recovery | Required when adding logos/icons, harsh environments |
Tip: Use ECC Level H when embedding icons in QR codes to ensure readability even when the center is obscured.
Encoding Modes
QR codes support different encoding modes optimized for specific character types:
| Mode | Character Set | Bits per Character | Example |
|---|---|---|---|
| Numeric | 0-9 | ~3.3 bits | Phone numbers, postal codes |
| Alphanumeric | 0-9, A-Z, space, $ % * + - . / : | ~5.5 bits | URLs (uppercase), product codes |
| Byte | ISO-8859-1, UTF-8 | 8 bits | Text, URLs (mixed case), binary data |
| Kanji | Shift JIS characters | 13 bits | Japanese text |
Note: The library automatically selects the most efficient encoding mode for your content.
Version and Size
QR codes come in 40 versions (sizes), from Version 1 (21×21 modules) to Version 40 (177×177 modules). Each version adds 4 modules per side.
- Version 1: 21×21 modules
- Version 2: 25×25 modules
- ...
- Version 40: 177×177 modules
The library automatically selects the minimum version that can fit your content based on the selected ECC level.
See Data Capacity Reference for practical capacities and full tables by version and ECC level.
Usage Examples
Basic Usage
Using Builder Pattern
using SkiaSharp.QrCode.Image;
var qrCode = new QRCodeImageBuilder("https://example.com")
.WithSize(800, 800)
.WithErrorCorrection(ECCLevel.H)
.WithQuietZone(4);
var pngBytes = qrCode.ToByteArray();
File.WriteAllBytes("qrcode.png", pngBytes);
Direct File Output
using SkiaSharp.QrCode.Image;
using var stream = File.OpenWrite("qrcode.png");
new QRCodeImageBuilder("https://example.com")
.WithSize(1024, 1024)
.WithErrorCorrection(ECCLevel.H)
.SaveTo(stream);
Raster Output (PNG / JPEG / WebP)
Default format is PNG. Switch with WithFormat() — quality (0–100) applies to lossy formats (JPEG, WebP).
using SkiaSharp;
using SkiaSharp.QrCode.Image;
// PNG (default)
var pngBytes = new QRCodeImageBuilder("https://example.com")
.WithSize(512, 512)
.ToByteArray();
// JPEG
var jpegBytes = new QRCodeImageBuilder("https://example.com")
.WithSize(512, 512)
.WithFormat(SKEncodedImageFormat.Jpeg, quality: 90)
.ToByteArray();
// WebP
var webpBytes = new QRCodeImageBuilder("https://example.com")
.WithSize(512, 512)
.WithFormat(SKEncodedImageFormat.Webp, quality: 80)
.ToByteArray();
// Or one-liner helpers
var bytes = QRCodeImageBuilder.GetImageBytes(
"https://example.com", SKEncodedImageFormat.Jpeg, ECCLevel.M, size: 512, quality: 90);
SVG Output (Vector)
SVG output draws the QR code as vector shapes, so it scales to any size without quality loss — ideal for print and web embedding. All builder options (colors, module shapes, gradients, finder patterns, icons) apply to SVG as well.
using SkiaSharp;
using SkiaSharp.QrCode.Image;
// One-liner: save to stream
using var stream = File.Create("qrcode.svg");
QRCodeImageBuilder.SaveSvg("https://example.com", stream);
// One-liner: SVG document string, e.g. for inline HTML embedding
var svg = QRCodeImageBuilder.GetSvgString("https://example.com");
// Builder: full styling support
var svgString = new QRCodeImageBuilder("https://example.com")
.WithModulePixelSize(10)
.WithErrorCorrection(ECCLevel.H)
.WithColors(codeColor: SKColor.Parse("1B9CFC"))
.ToSvgString(); // or SaveToSvg(stream) / SaveToSvg(bufferWriter) / GetSvgBytes(...)
Size options define the SVG viewport (in SVG units instead of pixels); WithFormat() does not apply to SVG output.
The root element always carries a viewBox, so the QR code scales its content when displayed at any size (<img>, CSS, or attribute-based sizing). Plain rectangular modules also get shape-rendering="crispEdges" to prevent antialiasing seams between modules; custom shapes (circles, rounded rects) keep antialiasing for smooth curves.
Tip
Default rectangle modules produce compact SVG (horizontal module runs merge into single <rect> elements). Custom module shapes and gradients render correctly but produce larger documents, since each module becomes an individual vector element. Icon images are embedded as base64 data URIs.
Choosing Image Size
| Goal | API | Notes |
|---|---|---|
| Keep module edges sharp / logo aligned | WithModulePixelSize(n) |
Output side = QR matrix size * n. Best default when using logos. |
| Also fit a fixed UI frame | WithModulePixelSize(n) + WithSize(w, h) |
Canvas must be >= content size. Extra space is centered padding (clearColor). Too-small canvas throws. |
| Only need a fixed pixel box | WithSize(w, h) |
Simple, but module size may become fractional when QR version changes. |
Recommended (module-aligned):
using SkiaSharp.QrCode.Image;
var qrCode = new QRCodeImageBuilder("https://example.com")
.WithModulePixelSize(10) // content = (QR matrix size in modules) * 10
.WithErrorCorrection(ECCLevel.H)
.WithQuietZone(4);
var pngBytes = qrCode.ToByteArray();
Recommended (module-aligned + fixed canvas):
using SkiaSharp;
using SkiaSharp.QrCode.Image;
var qrCode = new QRCodeImageBuilder("https://example.com")
.WithModulePixelSize(10)
.WithSize(512, 512) // must be >= content size
.WithColors(clearColor: SKColors.Transparent)
.WithErrorCorrection(ECCLevel.H);
var pngBytes = qrCode.ToByteArray();
Fixed box only (may use fractional module pixels):
using SkiaSharp.QrCode.Image;
var qrCode = new QRCodeImageBuilder("https://example.com")
.WithSize(512, 512)
.WithErrorCorrection(ECCLevel.H);
var pngBytes = qrCode.ToByteArray();
Advanced Usage
Request Veresion
"abc" can fit in Version 1, but we request Version 10 to show more dots. This can be useful for adding logo with short content.
using SkiaSharp;
using SkiaSharp.QrCode.Image;
new QRCodeImageBuilder("abc")
.WithSize(512, 512)
.WithVersion(10)
.ToByteArray();
Custom Colors
using SkiaSharp;
using SkiaSharp.QrCode.Image;
new QRCodeImageBuilder("https://example.com")
.WithSize(800, 800)
.WithColors(
codeColor: SKColor.Parse("#000080"), // Navy
backgroundColor: SKColor.Parse("#FFE4B5"), // Moccasin
clearColor: SKColors.Transparent)
.ToByteArray();
Gradient QR code
using SkiaSharp;
using SkiaSharp.QrCode.Image;
var gradient = new GradientOptions(
[SKColors.Blue, SKColors.Purple, SKColors.Pink],
GradientDirection.TopLeftToBottomRight,
[0f, 0.5f, 1f]);
var qrCode = new QRCodeImageBuilder("https://example.com")
.WithSize(800, 800)
.WithErrorCorrection(ECCLevel.H)
.WithGradient(gradient)
.WithModuleShape(RoundedRectangleModuleShape.Default, sizePercent: 0.9f);
var pngBytes = qrCode.ToByteArray();
QR code with Logo (icon only)
Prefer module-based sizing so the logo sits on the QR grid. See Choosing Image Size.
using SkiaSharp;
using SkiaSharp.QrCode.Image;
using var logo = SKBitmap.Decode(File.ReadAllBytes("logo.png"));
// Percent/pixel sizing (existing)
var iconByPercent = IconData.FromImage(logo, iconSizePercent: 15, iconBorderWidth: 10);
// Module-based sizing (recommended with WithModulePixelSize)
var iconByModules = IconData.FromImageByModules(logo, iconSizeModules: 7, iconBorderModules: 1);
var qrCode = new QRCodeImageBuilder("https://example.com")
.WithModulePixelSize(12)
// .WithSize(512, 512) // optional: larger canvas with centered padding
.WithErrorCorrection(ECCLevel.H) // High ECC recommended for icons
.WithIcon(iconByModules);
var pngBytes = qrCode.ToByteArray();
QR code with Logo (icon and text)
using SkiaSharp;
using SkiaSharp.QrCode.Image;
using var logo = SKBitmap.Decode(File.ReadAllBytes("logo.png"));
using var font = new SKFont
{
Size = 18,
Typeface = SKTypeface.FromFamilyName("sans-serif", SKFontStyle.Bold)
};
var icon = new IconData
{
// Default text is placed below the icon image, centered
Icon = new ImageTextIconShape(logo, "FooBar", SKColors.Black, font, textPadding: 2),
IconSizePercent = 13,
IconBorderWidth = 18,
};
var qrCode = new QRCodeImageBuilder("https://example.com")
.WithSize(800, 800)
.WithErrorCorrection(ECCLevel.H) // High ECC recommended for icons
.WithIcon(icon);
var pngBytes = qrCode.ToByteArray();
Custom Module Shapes
using SkiaSharp;
using SkiaSharp.QrCode.Image;
var qrCode = new QRCodeImageBuilder("https://example.com")
.WithSize(800, 800)
.WithModuleShape(CircleModuleShape.Default, sizePercent: 0.95f)
.WithColors(codeColor: SKColors.DarkBlue);
var pngBytes = qrCode.ToByteArray();
Custom Finder Pattern
var qrCode = new QRCodeImageBuilder("https://example.com")
.WithSize(512, 512)
.WithFinderPatternShape(RoundedRectangleFinderPatternShape.Default)
.WithColors(codeColor: SKColors.DarkBlue);
var pngBytes = qrCode.ToByteArray();
Gradient QR Code
var instagramGradient = new GradientOptions([
SKColor.Parse("FCAF45"), // Orange
SKColor.Parse("F77737"), // Orange-Red
SKColor.Parse("E1306C"), // Pink
SKColor.Parse("C13584"), // Purple
SKColor.Parse("833AB4") // Deep Purple
],
GradientDirection.TopLeftToBottomRight,
[0f, 0.25f, 0.5f, 0.75f, 1f]);
var qrCode = new QRCodeImageBuilder(content)
.WithSize(512, 512)
.WithColors(backgroundColor: SKColors.White, clearColor: SKColors.White)
.WithModuleShape(CircleModuleShape.Default, sizePercent: 0.95f)
.WithFinderPatternShape(RoundedRectangleCircleFinderPatternShape.Default)
.WithGradient(instagramGradient);
var pngBytes = qrCode.ToByteArray();
Low-Level Canvas Rendering
For maximum control over rendering:
using SkiaSharp;
using SkiaSharp.QrCode;
// Generate QR data
var qrData = QRCodeGenerator.CreateQrCode("https://example.com", ECCLevel.M, quietZoneSize: 4);
// Create canvas
var info = new SKImageInfo(800, 800);
using var surface = SKSurface.Create(info);
var canvas = surface.Canvas;
// Render QR code
canvas.Render(qrData, info.Width, info.Height);
// Save
using var image = surface.Snapshot();
using var data = image.Encode(SKEncodedImageFormat.Png, 100);
using var stream = File.OpenWrite("qrcode.png");
data.SaveTo(stream);
License
MIT
Acknowledgments
- aloisdeniel/Xam.Forms.QRCode : Qr Sample with Skia
- codebude/QRCoder : QRCode generation algorithms
Showing the top 20 packages that depend on SkiaSharp.QrCode.
| Packages | Downloads |
|---|---|
|
AtomUI.Desktop.Controls
AtomUI is an implementation of AntDesigin based on .NET technology, and is committed to bringing AntDesign's excellent and efficient design language and experience to the Avalonia/.NET cross-platform desktop software development field.
|
3 |
|
AtomUI.Controls
AtomUI is an Ant Design 6 component system for Avalonia/.NET desktop applications, including themed controls, design tokens, icons, native window integration and optional DataGrid, ColorPicker and Extras packages.
|
2 |
|
AtomUI.Controls
AtomUI is an implementation of AntDesigin based on .NET technology, and is committed to bringing AntDesign's excellent and efficient design language and experience to the Avalonia/.NET cross-platform desktop software development field.
|
2 |
|
AtomUI.Controls
AtomUI is an Ant Design 6 component system for Avalonia/.NET desktop applications, including themed controls, design tokens, icons, native window integration and optional DataGrid, ColorPicker, Extras and Labs packages.
|
2 |
|
AtomUI.Controls
AtomUI is an Ant Design 6 component system for Avalonia/.NET desktop applications, including themed controls, design tokens, icons, native window integration and optional DataGrid and ColorPicker packages.
|
2 |
|
AtomUI.Desktop.Controls
AtomUI is an implementation of AntDesigin based on .NET technology, and is committed to bringing AntDesign's excellent and efficient design language and experience to the Avalonia/.NET cross-platform desktop software development field.
|
2 |
.NET 10.0
- SkiaSharp (>= 4.148.0)
- SkiaSharp.NativeAssets.Win32 (>= 4.148.0)
- SkiaSharp.NativeAssets.macOS (>= 4.148.0)
.NET 8.0
- SkiaSharp (>= 4.148.0)
- SkiaSharp.NativeAssets.Win32 (>= 4.148.0)
- SkiaSharp.NativeAssets.macOS (>= 4.148.0)
.NET Standard 2.0
- SkiaSharp (>= 4.148.0)
- SkiaSharp.NativeAssets.Win32 (>= 4.148.0)
- SkiaSharp.NativeAssets.macOS (>= 4.148.0)
.NET Standard 2.1
- SkiaSharp (>= 4.148.0)
- SkiaSharp.NativeAssets.Win32 (>= 4.148.0)
- SkiaSharp.NativeAssets.macOS (>= 4.148.0)
| Version | Downloads | Last updated |
|---|---|---|
| 2.0.0-preview.2 | 2 | 2026/9/21 |
| 2.0.0-preview.1 | 1 | 2026/9/21 |
| 1.2.0 | 1 | 2026/9/21 |
| 1.1.1 | 1 | 2026/9/21 |
| 1.1.0 | 1 | 2026/9/21 |
| 1.0.1 | 1 | 2026/9/21 |
| 1.0.0 | 1 | 2026/9/21 |
| 0.12.0 | 2 | 2026/9/21 |
| 0.11.0 | 1 | 2026/9/21 |
| 0.10.0 | 1 | 2026/9/21 |
| 0.9.0 | 1 | 2026/9/21 |
| 0.8.0 | 1 | 2026/9/21 |
| 0.7.0 | 2 | 2026/9/21 |
| 0.6.0 | 1 | 2026/9/21 |
| 0.5.0 | 1 | 2026/9/21 |
| 0.4.1 | 1 | 2026/9/21 |
| 0.3.2 | 1 | 2026/9/21 |
| 0.3.1 | 1 | 2026/9/21 |
| 0.3.0 | 1 | 2026/9/21 |
| 0.2.0 | 1 | 2026/9/21 |
| 0.1.0 | 1 | 2026/9/21 |