BarcodeImageRenderer Class
Provides methods to render a linear barcode as an Image<TPixel>, or to draw it on a canvas.
public static class BarcodeImageRendererRemarks
The drawing is the scene of BarcodeRenderer.CreateScene, drawn by SceneImageRenderer: the image is the same as the SVG of BarcodeRenderer.ToSvg, human-readable text included.
Methods
| Name | Description |
|---|---|
| DrawBarcode(DrawingCanvas, Barcode, PointD, BarcodeRenderOptions?, SceneImageOptions?) | Draws the barcode on a canvas, as vector shapes and text. |
| MeasureBarcode(Barcode, BarcodeRenderOptions?, SceneImageOptions?) | Measures the rectangle that BarcodeImageRenderer.DrawBarcode covers, quiet zone and text included. |
| ToImage(Barcode, BarcodeRenderOptions?, SceneImageOptions?) | Renders the barcode as an image of the size of its scene times SceneImageOptions.Scale, rounded up. |
DrawBarcode(DrawingCanvas, Barcode, PointD, BarcodeRenderOptions?, SceneImageOptions?)
BarcodeImageRenderer.csDraws the barcode on a canvas, as vector shapes and text.
public static RectangleD DrawBarcode(this DrawingCanvas canvas, Barcode barcode, PointD position, BarcodeRenderOptions? options = null, SceneImageOptions? imageOptions = null)Parameters
canvasDrawingCanvas- The canvas to draw on.
barcodeBarcode- The barcode to draw.
positionPointD- The top-left corner of the drawing. It is rounded to whole units when
BarcodeRenderOptions.SnapToPixelsis set. optionsBarcodeRenderOptions?- 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 and text included.
Exceptions
ArgumentNullExceptionbarcodeorBarcodeRenderOptions.DarkPaintisnull.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 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 BarcodeRenderOptions.DarkPaint, so adjacent modules have no seam. Use BarcodeImageRenderer.MeasureBarcode to know the size before drawing.
MeasureBarcode(Barcode, BarcodeRenderOptions?, SceneImageOptions?)
BarcodeImageRenderer.csMeasures the rectangle that BarcodeImageRenderer.DrawBarcode covers, quiet zone and text included.
public static RectangleD MeasureBarcode(Barcode barcode, BarcodeRenderOptions? options = null, SceneImageOptions? imageOptions = null)Parameters
barcodeBarcode- The barcode to measure.
optionsBarcodeRenderOptions?- 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
ArgumentNullExceptionbarcodeorBarcodeRenderOptions.DarkPaintisnull.ArgumentOutOfRangeException- An option is out of range, or the dimensions of the drawing are too large.
ToImage(Barcode, BarcodeRenderOptions?, SceneImageOptions?)
BarcodeImageRenderer.csRenders the barcode as an image of the size of its scene times SceneImageOptions.Scale, rounded up.
public static Image<Rgba32> ToImage(this Barcode barcode, BarcodeRenderOptions? options = null, SceneImageOptions? imageOptions = null)Parameters
barcodeBarcode- The barcode to render.
optionsBarcodeRenderOptions?- 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
ArgumentNullExceptionbarcodeorBarcodeRenderOptions.DarkPaintisnull.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 BarcodeRenderOptions.SnapToPixels and scale, the modules are whole pixels and the image has two colors when the paints are solid. With a null BarcodeRenderOptions.LightPaint, the background is transparent.