QRCodeImageRenderer Class
Provides methods to render a QR code as an Image<TPixel>, or to draw it on a canvas.
public static class QRCodeImageRendererRemarks
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
| Name | Description |
|---|---|
| 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.csDraws 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
canvasDrawingCanvas- The canvas to draw on.
qrCodeQRCode- The QR code to draw.
positionPointD- The top-left corner of the drawing. It is rounded to whole units when
QRCodeRenderOptions.SnapToPixelsis set. optionsQRCodeRenderOptions?- The rendering options, or
nullfor the defaults. imageOptionsSceneImageOptions?- The options of the image renderer (scale, fonts), or
nullfor the defaults.
Returns
RectangleD The rectangle the drawing covers, quiet zone included.
Exceptions
ArgumentNullExceptionqrCodeorQRCodeRenderOptions.DarkPaintisnull.ArgumentException- A coordinate of
positionis 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.csMeasures the rectangle that QRCodeImageRenderer.DrawQRCode covers, quiet zone included.
public static RectangleD MeasureQRCode(QRCode qrCode, QRCodeRenderOptions? options = null, SceneImageOptions? imageOptions = null)Parameters
qrCodeQRCode- The QR code to measure.
optionsQRCodeRenderOptions?- The rendering options, or
nullfor the defaults. imageOptionsSceneImageOptions?- The options of the image renderer (scale, fonts), or
nullfor the defaults.
Returns
RectangleD The size of the drawing, as a rectangle located at the origin.
Exceptions
ArgumentNullExceptionqrCodeorQRCodeRenderOptions.DarkPaintisnull.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.csRenders 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
qrCodeQRCode- The QR code to render.
optionsQRCodeRenderOptions?- The rendering options, or
nullfor the defaults. imageOptionsSceneImageOptions?- The options of the image renderer (scale, fonts), or
nullfor the defaults.
Returns
Image<Rgba32> A single-frame image. The caller owns it and must dispose it.
Exceptions
ArgumentNullExceptionqrCodeorQRCodeRenderOptions.DarkPaintisnull.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.