Barcode2DImageRenderer Class

Provides methods to render a two-dimensional barcode (Data Matrix, PDF417, Aztec) as an Image<TPixel>, or to draw it on a canvas.

public static class Barcode2DImageRenderer

Remarks

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

Methods

NameDescription
DrawBarcode2D(DrawingCanvas, Barcode2D, PointD, Barcode2DRenderOptions?, SceneImageOptions?)Draws the barcode on a canvas, as vector shapes.
MeasureBarcode2D(Barcode2D, Barcode2DRenderOptions?, SceneImageOptions?)Measures the rectangle that Barcode2DImageRenderer.DrawBarcode2D covers, quiet zone included.
ToImage(Barcode2D, Barcode2DRenderOptions?, SceneImageOptions?)Renders the barcode as an image of the size of its scene times SceneImageOptions.Scale, rounded up.

DrawBarcode2D(DrawingCanvas, Barcode2D, PointD, Barcode2DRenderOptions?, SceneImageOptions?)

Barcode2DImageRenderer.cs

Draws the barcode on a canvas, as vector shapes.

public static RectangleD DrawBarcode2D(this DrawingCanvas canvas, Barcode2D barcode, PointD position, Barcode2DRenderOptions? options = null, SceneImageOptions? imageOptions = null)

Parameters

canvas DrawingCanvas
The canvas to draw on.
barcode Barcode2D
The barcode to draw.
position PointD
The top-left corner of the drawing. It is rounded to whole units when Barcode2DRenderOptions.SnapToPixels is set.
options Barcode2DRenderOptions?
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
barcode or Barcode2DRenderOptions.DarkPaint 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 barcode 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 Barcode2DRenderOptions.DarkPaint, so adjacent modules have no seam. Use Barcode2DImageRenderer.MeasureBarcode2D to know the size before drawing.

MeasureBarcode2D(Barcode2D, Barcode2DRenderOptions?, SceneImageOptions?)

Barcode2DImageRenderer.cs

Measures the rectangle that Barcode2DImageRenderer.DrawBarcode2D covers, quiet zone included.

public static RectangleD MeasureBarcode2D(Barcode2D barcode, Barcode2DRenderOptions? options = null, SceneImageOptions? imageOptions = null)

Parameters

barcode Barcode2D
The barcode to measure.
options Barcode2DRenderOptions?
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
barcode or Barcode2DRenderOptions.DarkPaint is null.
ArgumentOutOfRangeException
An option is out of range, or the dimensions of the drawing are too large.

ToImage(Barcode2D, Barcode2DRenderOptions?, SceneImageOptions?)

Barcode2DImageRenderer.cs

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

public static Image<Rgba32> ToImage(this Barcode2D barcode, Barcode2DRenderOptions? options = null, SceneImageOptions? imageOptions = null)

Parameters

barcode Barcode2D
The barcode to render.
options Barcode2DRenderOptions?
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
barcode or Barcode2DRenderOptions.DarkPaint 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 Barcode2DRenderOptions.SnapToPixels and scale, the modules are whole pixels and the image has two colors when the paints are solid. With a null Barcode2DRenderOptions.LightPaint, the background is transparent.