Lyo.QRCode
1.0.3
dotnet add package Lyo.QRCode --version 1.0.3
NuGet\Install-Package Lyo.QRCode -Version 1.0.3
<PackageReference Include="Lyo.QRCode" Version="1.0.3" />
<PackageVersion Include="Lyo.QRCode" Version="1.0.3" />
<PackageReference Include="Lyo.QRCode" />
paket add Lyo.QRCode --version 1.0.3
#r "nuget: Lyo.QRCode, 1.0.3"
#:package Lyo.QRCode@1.0.3
#addin nuget:?package=Lyo.QRCode&version=1.0.3
#tool nuget:?package=Lyo.QRCode&version=1.0.3
Lyo.QRCode
QR code generation and reading for Lyo: IQRCodeService, QRCodeBuilder, ISO Model 2 encoding in-box (BuiltInQRCodeService), optional QRCoder adapter package Lyo.QRCode.QRCoder, and typed payload helpers (Lyo.QRCode.Payloads) for Wi‑Fi, URLs, vCard, mailto:, etc.
Examples
Quick start (built-in encoder)
using Lyo.QRCode;
using Lyo.QRCode.Models;
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.AddQRCodeService(o => {
o.DefaultSize = 16; // pixels per module, not total width
o.DefaultFormat = QRCodeFormat.Png;
o.DefaultErrorCorrectionLevel = QRCodeErrorCorrectionLevel.Medium;
});
var qr = services.BuildServiceProvider().GetRequiredService<IQRCodeService>();
var result = await qr.GenerateAsync("https://example.com");
if (result.IsSuccess && result is QRCodeResult r && r.ImageBytes != null)
await File.WriteAllBytesAsync("qr.png", r.ImageBytes);
Typed payload (Wi‑Fi example)
using Lyo.QRCode;
using Lyo.QRCode.Payloads;
var payload = new WifiQrPayload("MySSID", "secret", QrWifiSecurityType.Wpa);
var (_, opts) = QRCodeBuilder.New()
.WithPayload(payload)
.WithFormat(QRCodeFormat.Png)
.WithSize(12)
.Build();
Architecture
| Piece | Role |
|---|---|
IQRCodeService |
Generate to memory, stream, file; batch; ReadFromImageAsync (ZXing). |
BuiltInQRCodeService |
In-library PNG/SVG rasterization; no QRCoder NuGet for encode. JPEG/BMP not supported here (platform / format limits). |
Lyo.QRCode.QRCoder |
Optional QRCoderQRCodeService + AddQRCoderQrCodeService for JPEG/Bitmap on Windows and QRCoder-based render path. |
QRCodeBuilder |
Fluent QRCodeOptions + WithData / WithPayload(IQrPayload). |
Payloads |
IQrPayload, QrPayloadKind, WifiQrPayload, HttpUrlPayload, contacts, URI schemes, messaging URLs — all serialize to the string passed to GenerateAsync. |
Optional: QRCoder package
Add project/package reference to Lyo.QRCode.QRCoder and call AddQRCoderQrCodeService (or AddQRCoderQrCodeServiceFromConfiguration) instead of or in addition to * *AddQRCodeService**, depending on how you register IQRCodeService.
Payload helpers (Lyo.QRCode.Payloads)
- Wi‑Fi (
WifiQrPayload) — OmitsH:when the SSID is not hidden (better phone compatibility thanH:false). Open networks omitP(notP:;). - SMS (
SmsPayload) — Defaults tosms:URI scheme;smsto:is opt-in (some Android SMS apps crash on longsmsto:bodies). Very long URIs throw (* *MaxSmsQrUriLength**) to avoid app crashes.
Key options
QRCodeOptions.Size— Pixels per module (each black/white square), not the full image width. Total size ≈ module count per side ×Size(decoration applied separately may grow that further).QRCodeOptions.Icon— Hint only for the encoder: the only field consumed isIconSizePercent, which bumps the effective ECC level so a planned center logo doesn't break scanning.IconBytes,IconFilePath, andDrawIconBorderare metadata for the consumer's overlay call — the QR encoder never composites the icon. Apply the actual overlay (and any frame/caption/padding) post-generation throughLyo.Images.IImageDecorationService(see migration note below).
Key options — Migration: decoration moved out of the encoder
QRCodeOptions.Frame, QRCodeBuilder.WithFrame(...), and the optional IImageService / IQrFrameLayoutService constructor parameters on BuiltInQRCodeService are gone.
Compose icons and chrome on the returned bytes with Lyo.Images:
using Lyo.Images;
using Lyo.Images.Builders;
using Lyo.Common.Enums;
var qr = await qrService.GenerateAsync(data, options);
var qrBytes = ((QRCodeResult)qr).ImageBytes!;
var decorated = await decoration.Pipeline(qrBytes)
.Overlay(logoBytes, b => b.WithOverlaySizePercent(18).WithPadColor("#FFFFFF").WithBorder("#000000"))
.AddCaption(b => b.WithText("Scan Me").WithNotch())
.AddOuterPadding(b => b.WithPanelColor("#FFFFFF").WithCornerRadius(16))
.AddFrame(b => b.WithStrokeColor("#1e293b").WithStrokeWidth(2).WithCornerRadius(16))
.ToByteArrayAsync(ImageFormat.Png);
OverlayAsync works on PNG (raster) and SVG (embeds a base64 PNG <image> before </svg>); the other primitives require raster input.
Error correction
QRCodeErrorCorrectionLevel: Low (~7%), Medium (~15%), Quartile (~25%), High (~30%) recovery. Higher levels tolerate damage and logos better but increase symbol version for the same payload.
Blazor UI (optional)
Lyo.QRCode.Web.Components—QrCodeWorkbenchand related MudBlazor components.
Dependencies
Generated from ProjectReference / PackageReference (same model as docs/Lyo.ProjectGraph.html).
Lyo.Common— (direct, lyo)Lyo.Exceptions— (direct, lyo)Lyo.Metrics— (direct, lyo)Lyo.Result— (direct, lyo)Microsoft.Extensions.Configuration.Binder10.0.5— (direct, microsoft)Microsoft.Extensions.DependencyInjection.Abstractions10.0.5— (direct, microsoft)Microsoft.Extensions.Logging.Abstractions10.0.5— (direct, microsoft)SixLabors.ImageSharp3.1.12— (direct, third-party)ZXing.Net0.16.11— (direct, third-party)ZXing.Net.Bindings.ImageSharp.V30.16.18— (direct, third-party)Microsoft.Extensions.Options.ConfigurationExtensions10.0.5— (transitive, microsoft)System.Memory4.6.3— (transitive, microsoft, netstandard2.0)System.Text.Json10.0.5— (transitive, microsoft, netstandard2.0)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Lyo.Common (>= 1.0.3)
- Lyo.Exceptions (>= 1.0.3)
- Lyo.Metrics (>= 1.0.3)
- Lyo.Result (>= 1.0.3)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.5)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.5)
- SixLabors.ImageSharp (>= 3.1.12)
- ZXing.Net (>= 0.16.11)
- ZXing.Net.Bindings.ImageSharp.V3 (>= 0.16.18)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Lyo.QRCode:
| Package | Downloads |
|---|---|
|
Lyo.QRCode.Web.Components
Reusable Blazor components for QR code generation and preview workflows. |
|
|
Lyo.QRCode.QRCoder
QRCoder implementation for Lyo.QRCode - QR code generation service using QRCoder library. |
GitHub repositories
This package is not used by any popular GitHub repositories.