QRCodeImageRenderer Class

Provides methods to render a QR code as an Image<TPixel>, or to draw it on a canvas.

public static class QRCodeImageRenderer

Remarks

The drawing is the scene of QRCodeRenderer.CreateScene, drawn by SceneImageRenderer: the image is the same as the SVG of QRCodeRenderer.ToSvg, logo included.

Methods

NameDescription
DrawQRCode(DrawingCanvas, QRCode, PointD, QRCodeRenderOptions?, SceneImageOptions?)Draws the QR code on a canvas, as vector shapes and its logo.
MeasureQRCode(QRCode, QRCodeRenderOptions?, SceneImageOptions?)Measures the rectangle that QRCodeImageRenderer.DrawQRCode covers, quiet zone included.
ToImage(QRCode, QRCodeRenderOptions?, SceneImageOptions?)Renders the QR code as an image of the size of its scene times SceneImageOptions.Scale, rounded up.

DrawQRCode(DrawingCanvas, QRCode, PointD, QRCodeRenderOptions?, SceneImageOptions?)

QRCodeImageRenderer.cs

Draws the QR code on a canvas, as vector shapes and its logo.

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

Parameters

canvas DrawingCanvas
The canvas to draw on.
qrCode QRCode
The QR code to draw.
position PointD
The top-left corner of the drawing. It is rounded to whole units when QRCodeRenderOptions.SnapToPixels is set.
options QRCodeRenderOptions?
The rendering options, or null for the defaults.
imageOptions SceneImageOptions?
The options of the image renderer (scale, fonts), or null for the defaults.

Returns

RectangleD The rectangle the drawing covers, quiet zone included.

Exceptions

ArgumentNullException
qrCode or QRCodeRenderOptions.DarkPaint is null.
ArgumentException
A coordinate of position is not a finite number.
ArgumentException
The data of the logo is not a PNG, JPEG, GIF or WebP file.
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 QRCodeRenderOptions.DarkPaint, so adjacent modules have no seam. Use QRCodeImageRenderer.MeasureQRCode to know the size before drawing.

MeasureQRCode(QRCode, QRCodeRenderOptions?, SceneImageOptions?)

QRCodeImageRenderer.cs

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

public static RectangleD MeasureQRCode(QRCode qrCode, QRCodeRenderOptions? options = null, SceneImageOptions? imageOptions = null)

Parameters

qrCode QRCode
The QR code to measure.
options QRCodeRenderOptions?
The rendering options, or null for the defaults.
imageOptions SceneImageOptions?
The options of the image renderer (scale, fonts), or null for the defaults.

Returns

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

Exceptions

ArgumentNullException
qrCode or QRCodeRenderOptions.DarkPaint is null.
ArgumentOutOfRangeException
An option is out of range, or the dimensions of the drawing are too large.
ArgumentException
The data of the logo is not a PNG, JPEG, GIF or WebP file.

ToImage(QRCode, QRCodeRenderOptions?, SceneImageOptions?)

QRCodeImageRenderer.cs

Renders the QR code as an image of the size of its scene times SceneImageOptions.Scale, rounded up.

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

Parameters

qrCode QRCode
The QR code to render.
options QRCodeRenderOptions?
The rendering options, or null for the defaults.
imageOptions SceneImageOptions?
The options of the image renderer (scale, fonts), or null for the defaults.

Returns

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

Exceptions

ArgumentNullException
qrCode or QRCodeRenderOptions.DarkPaint is null.
ArgumentOutOfRangeException
An option is out of range, or the image dimensions are too large.
ArgumentException
The data of the logo is not a PNG, JPEG, GIF or WebP file.
ImageResourceLimitException
The image exceeds a limit of ImageConfiguration.Default.

Remarks

With the default QRCodeRenderOptions.SnapToPixels and scale, the modules are whole pixels and the image has two colors when the paints are solid. With a null QRCodeRenderOptions.LightPaint, the background is transparent.