QRCodeImageRenderer Class

Provides methods to render a QR code as an Image<TPixel>.

public static class QRCodeImageRenderer

Methods

NameDescription
DrawQRCode(DrawingCanvas, QRCode, PointD, QRCodeDrawingOptions?)Draws the QR code on a canvas, as a vector shape.
MeasureQRCode(QRCode, QRCodeDrawingOptions?)Measures the rectangle that QRCodeImageRenderer.DrawQRCode covers, quiet zone included.
ToImage(QRCode, QRCodeDrawingOptions?)Renders the QR code as an image: what QRCodeImageRenderer.DrawQRCode draws on a canvas of the size QRCodeImageRenderer.MeasureQRCode gives, rounded up.

DrawQRCode(DrawingCanvas, QRCode, PointD, QRCodeDrawingOptions?)

QRCodeImageRenderer.cs

Draws the QR code on a canvas, as a vector shape.

public static RectangleD DrawQRCode(this DrawingCanvas canvas, QRCode qrCode, PointD position, QRCodeDrawingOptions? options = null)

Parameters

canvas DrawingCanvas
The canvas to draw on.
qrCode QRCode
The QR code to draw.
position PointD
The top-left corner of the quiet zone. It is rounded to whole units when QRCodeDrawingOptions.SnapToPixels is set.
options QRCodeDrawingOptions?
The drawing options, or null for the defaults.

Returns

RectangleD The rectangle the drawing covers, quiet zone included.

Exceptions

ArgumentNullException
qrCode or QRCodeDrawingOptions.DarkBrush is null.
ArgumentException
A coordinate of position is not a finite number.
ArgumentOutOfRangeException
An option is out of range, or the magnitude of a coordinate of the drawing exceeds 16777216.
InvalidOperationException
The callback that received the canvas has returned.
ImageResourceLimitException
The working storage would exceed the allocation limit.
OperationCanceledException
The drawing was canceled.

Remarks

The QR code is drawn in the coordinates of the canvas, so the transform, clip and layers of the canvas apply. The dark modules are one shape, painted with QRCodeDrawingOptions.DarkBrush, so adjacent modules have no seam. Use QRCodeImageRenderer.MeasureQRCode to know the size before drawing.

MeasureQRCode(QRCode, QRCodeDrawingOptions?)

QRCodeImageRenderer.cs

Measures the rectangle that QRCodeImageRenderer.DrawQRCode covers, quiet zone included.

public static RectangleD MeasureQRCode(QRCode qrCode, QRCodeDrawingOptions? options = null)

Parameters

qrCode QRCode
The QR code to measure.
options QRCodeDrawingOptions?
The drawing options, or null for the defaults.

Returns

RectangleD The size of the drawing, as a rectangle located at the origin.

Exceptions

ArgumentNullException
qrCode is null.
ArgumentOutOfRangeException
An option is out of range.

ToImage(QRCode, QRCodeDrawingOptions?)

QRCodeImageRenderer.cs

Renders the QR code as an image: what QRCodeImageRenderer.DrawQRCode draws on a canvas of the size QRCodeImageRenderer.MeasureQRCode gives, rounded up.

public static Image<Rgba32> ToImage(this QRCode qrCode, QRCodeDrawingOptions? options = null)

Parameters

qrCode QRCode
The QR code to render.
options QRCodeDrawingOptions?
The drawing options, or null for the defaults.

Returns

Image<Rgba32> A single-frame image. The caller owns it and must dispose it.

Exceptions

ArgumentNullException
qrCode or QRCodeDrawingOptions.DarkBrush is null.
ArgumentOutOfRangeException
An option is out of range, or the image dimensions are too large.
ImageResourceLimitException
The image exceeds a limit of ImageConfiguration.Default.

Remarks

With the default QRCodeDrawingOptions.SnapToPixels, the modules are whole pixels and the image has two colors when the brushes are solid. With a null QRCodeDrawingOptions.LightBrush, the background is transparent.