QRCodeImageRenderer Class
Provides methods to render a QR code as an Image<TPixel>.
public static class QRCodeImageRendererMethods
| Name | Description |
|---|---|
| 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.csDraws 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
canvasDrawingCanvas- The canvas to draw on.
qrCodeQRCode- The QR code to draw.
positionPointD- The top-left corner of the quiet zone. It is rounded to whole units when
QRCodeDrawingOptions.SnapToPixelsis set. optionsQRCodeDrawingOptions?- The drawing options, or
nullfor the defaults.
Returns
RectangleD The rectangle the drawing covers, quiet zone included.
Exceptions
ArgumentNullExceptionqrCodeorQRCodeDrawingOptions.DarkBrushisnull.ArgumentException- A coordinate of
positionis 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.csMeasures the rectangle that QRCodeImageRenderer.DrawQRCode covers, quiet zone included.
public static RectangleD MeasureQRCode(QRCode qrCode, QRCodeDrawingOptions? options = null)Parameters
qrCodeQRCode- The QR code to measure.
optionsQRCodeDrawingOptions?- The drawing options, or
nullfor the defaults.
Returns
RectangleD The size of the drawing, as a rectangle located at the origin.
Exceptions
ArgumentNullExceptionqrCodeisnull.ArgumentOutOfRangeException- An option is out of range.
ToImage(QRCode, QRCodeDrawingOptions?)
QRCodeImageRenderer.csRenders 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
qrCodeQRCode- The QR code to render.
optionsQRCodeDrawingOptions?- The drawing options, or
nullfor the defaults.
Returns
Image<Rgba32> A single-frame image. The caller owns it and must dispose it.
Exceptions
ArgumentNullExceptionqrCodeorQRCodeDrawingOptions.DarkBrushisnull.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.