BarcodeLogo Class

A logo drawn over the center of a QR code (QRCodeRenderOptions.Logo).

public sealed class BarcodeLogo

Remarks

The image keeps its proportions and is centered in a square of BarcodeLogo.SizePercent of the side of the drawing. By default, the modules under the logo are not drawn (BarcodeLogo.ClearModules): the logo sits on a clean area, snapped to whole modules, instead of over half-visible modules.

The scanner recovers the missing modules with the error correction of the QR code, so create the QR code with ErrorCorrectionLevel.H and keep the logo small. When the modules are cleared, rendering checks that the error correction can recover them, and throws an ArgumentOutOfRangeException when it cannot.

Constructors

NameDescription
BarcodeLogo(ReadOnlyMemory<byte>)Initializes a new instance of the BarcodeLogo class.

BarcodeLogo(ReadOnlyMemory<byte>)

BarcodeLogo.cs

Initializes a new instance of the BarcodeLogo class.

public BarcodeLogo(ReadOnlyMemory<byte> data)

Parameters

data ReadOnlyMemory<byte>
The bytes of a PNG, JPEG, GIF or WebP file.

Properties

NameDescription
BackdropCornerRadiusGets or sets the radius of the corners of the backdrop, in modules. Default is 0: square corners.
BackdropPaintGets or sets the paint of the cleared area, drawn under the logo. Default is null: the light paint of the QR code shows.
ClearModulesGets or sets a value indicating whether the modules under the logo are not drawn. Default is true.
DataGets the bytes of the image: a PNG, JPEG, GIF or WebP file.
MarginModulesGets or sets the number of modules cleared around the logo, on each side. Default is 0.
SizePercentGets or sets the size of the logo, as a percentage of the smallest side of the drawing, quiet zone included. Default is 20.

BackdropCornerRadius

BarcodeLogo.cs

Gets or sets the radius of the corners of the backdrop, in modules. Default is 0: square corners.

public double BackdropCornerRadius { get; set; }

Property value

double

Remarks

The radius is at most half the smallest side of the backdrop. Only the backdrop is rounded: the cleared area stays a rectangle of whole modules. Valid values are 0 or more.

BackdropPaint

BarcodeLogo.cs

Gets or sets the paint of the cleared area, drawn under the logo. Default is null: the light paint of the QR code shows.

public ScenePaint? BackdropPaint { get; set; }

Property value

ScenePaint?

Remarks

Set a backdrop when the QR code has no light paint (a transparent background), or to draw the logo on a color of its own. Keep it light: a dark backdrop reads as dark modules. Ignored when BarcodeLogo.ClearModules is false.

ClearModules

BarcodeLogo.cs

Gets or sets a value indicating whether the modules under the logo are not drawn. Default is true.

public bool ClearModules { get; set; }

Property value

bool

Remarks

The cleared area is the smallest rectangle of whole modules that contains the logo, grown by BarcodeLogo.MarginModules on each side. A logo that is not square covers a band of its square, and only that band is cleared; an image with Exif metadata clears its whole square, as viewers that apply its orientation can turn it. Its modules are not drawn, so the light paint of the QR code shows under the logo, or BarcodeLogo.BackdropPaint when it is set.

Rendering throws an ArgumentOutOfRangeException when the area covers a finder pattern, a timing pattern, the format information or the version information, which the scanner needs to locate and read the code, or when an error correction block of the QR code has more codewords in the area than its error correction level can recover. The alignment patterns in the area are cleared, like the data. Set false to draw the modules under the logo, without this check.

Gets the bytes of the image: a PNG, JPEG, GIF or WebP file.

public ReadOnlyMemory<byte> Data { get; }

Property value

ReadOnlyMemory<byte>

Remarks

SVG output embeds the bytes as a data URI, and image and PDF output decode them, so every output draws the same logo. Rendering throws an ArgumentException when the data is not one of these formats.

MarginModules

BarcodeLogo.cs

Gets or sets the number of modules cleared around the logo, on each side. Default is 0.

public int MarginModules { get; set; }

Property value

int

Remarks

The cleared area already ends on module boundaries, so there is up to a module of space between the logo and the nearest dark module. A margin of 1 separates them more clearly, but clears more modules. Ignored when BarcodeLogo.ClearModules is false. Valid values are 0 or more.

SizePercent

BarcodeLogo.cs

Gets or sets the size of the logo, as a percentage of the smallest side of the drawing, quiet zone included. Default is 20.

public int SizePercent { get; set; }

Property value

int

Remarks

Valid values are between 1 and 100.