Meziantou.Framework.QRCode.Imaging
1.0.1
Prefix Reserved
dotnet add package Meziantou.Framework.QRCode.Imaging --version 1.0.1
NuGet\Install-Package Meziantou.Framework.QRCode.Imaging -Version 1.0.1
<PackageReference Include="Meziantou.Framework.QRCode.Imaging" Version="1.0.1" />
<PackageVersion Include="Meziantou.Framework.QRCode.Imaging" Version="1.0.1" />
<PackageReference Include="Meziantou.Framework.QRCode.Imaging" />
paket add Meziantou.Framework.QRCode.Imaging --version 1.0.1
#r "nuget: Meziantou.Framework.QRCode.Imaging, 1.0.1"
#:package Meziantou.Framework.QRCode.Imaging@1.0.1
#addin nuget:?package=Meziantou.Framework.QRCode.Imaging&version=1.0.1
#tool nuget:?package=Meziantou.Framework.QRCode.Imaging&version=1.0.1
Meziantou.Framework.QRCode.Imaging
Renders the QR codes and barcodes of Meziantou.Framework.QRCode as Meziantou.Framework.Imaging images. The resulting Image<Rgba32> can be saved in any format the library supports (PNG, WebP, JPEG, GIF, AVIF, ...), resized, or drawn onto another image.
Meziantou.Framework.QRCode already writes PNG files on its own (ToPng), with no dependency. Use this package when you need another format or want to process the image further.
Usage
The examples use the Meziantou.Framework (QR codes and barcodes), Meziantou.Framework.Imaging (images) and
Meziantou.Framework.Imaging.Formats (encoders) namespaces.
var qrCode = QRCode.Create("https://www.meziantou.net", ErrorCorrectionLevel.M);
// Default options: 10 pixels per module, a 4-module quiet zone, black on white
using var image = qrCode.ToImage();
Assert.Equal((330, 330), (image.Width, image.Height));
// Save to a file (image.Save("qrcode.webp", new WebPEncoder())) or to a stream
using var webp = new MemoryStream();
image.Save(webp, new WebPEncoder());
// Custom options
using var customImage = qrCode.ToImage(new QRCodeImageOptions
{
ModuleSize = 4,
QuietZoneModules = 2,
DarkColor = new Rgba32(0x00, 0x33, 0x66),
LightColor = Colors.Transparent,
});
Assert.Equal((116, 116), (customImage.Width, customImage.Height));
Assert.Equal(Colors.Transparent, customImage.Frames[0][0, 0]);
Assert.Equal(new Rgba32(0x00, 0x33, 0x66), customImage.Frames[0][8, 8]);
// An indexed PNG stores the two colors in a palette, as ToPng does
using var png = new MemoryStream();
customImage.Save(png, new PngEncoder { PixelLayout = PngPixelLayout.Indexed });
Barcodes work the same way:
var barcode = Barcode.CreateEan13("5901234123457");
using var image = barcode.ToImage(new BarcodeImageOptions { ModuleWidth = 3, ModuleHeight = 100 });
Assert.Equal((345, 100), (image.Width, image.Height));
Drawing a QR code onto an existing image:
using var ticket = new Image<Rgba32>(400, 200, Colors.White); // or Image.Load<Rgba32>("ticket.png")
using var qrCodeImage = QRCode.Create("TICKET-0042").ToImage(new QRCodeImageOptions { ModuleSize = 4 });
ticket.Draw(canvas => canvas.DrawImage(qrCodeImage.Frames[0], new PointD(16, 16)));
Assert.Equal(Colors.Black, ticket.Frames[0][32, 32]); // the top-left finder pattern, after the 16-pixel quiet zone
// Save to a file (ticket.Save("ticket-with-qrcode.png")) or to a stream
using var png = new MemoryStream();
ticket.Save(png, new PngEncoder());
Options
QRCodeImageOptions |
Default | Description |
|---|---|---|
ModuleSize |
10 | Size of each module, in pixels |
QuietZoneModules |
4 | Number of quiet zone modules around the QR code |
DarkColor |
Colors.Black |
Color of dark modules |
LightColor |
Colors.White |
Color of light modules and of the quiet zone |
BarcodeImageOptions |
Default | Description |
|---|---|---|
ModuleWidth |
2 | Width of each module, in pixels |
ModuleHeight |
80 | Height of each module, in pixels |
QuietZoneModules |
10 | Number of quiet zone modules on the left and right sides |
DarkColor |
Colors.Black |
Color of dark modules |
LightColor |
Colors.White |
Color of light modules and of the quiet zone |
| 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. net11.0 is compatible. |
-
net10.0
- Meziantou.Framework.Imaging (>= 1.2.1)
- Meziantou.Framework.QRCode (>= 2.0.4)
-
net11.0
- Meziantou.Framework.Imaging (>= 1.2.1)
- Meziantou.Framework.QRCode (>= 2.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.