BarcodeImageRenderer Class
Provides methods to render a barcode as an Image<TPixel>.
public static class BarcodeImageRendererMethods
| Name | Description |
|---|---|
| DrawBarcode(DrawingCanvas, Barcode, PointD, BarcodeDrawingOptions?) | Draws the barcode on a canvas, as a vector shape, with its human-readable text when a font is set. |
| MeasureBarcode(Barcode, BarcodeDrawingOptions?) | Measures the rectangle that BarcodeImageRenderer.DrawBarcode covers, quiet zone and text included. |
| ToImage(Barcode, BarcodeDrawingOptions?) | Renders the barcode as an image: what BarcodeImageRenderer.DrawBarcode draws on a canvas of the size BarcodeImageRenderer.MeasureBarcode gives, rounded up. |
DrawBarcode(DrawingCanvas, Barcode, PointD, BarcodeDrawingOptions?)
BarcodeImageRenderer.csDraws the barcode on a canvas, as a vector shape, with its human-readable text when a font is set.
public static RectangleD DrawBarcode(this DrawingCanvas canvas, Barcode barcode, PointD position, BarcodeDrawingOptions? options = 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
BarcodeDrawingOptions.SnapToPixelsis set. optionsBarcodeDrawingOptions?- The drawing options, or
nullfor the defaults.
Returns
RectangleD The rectangle the drawing covers, quiet zone and text included.
Exceptions
ArgumentNullExceptionbarcodeorBarcodeDrawingOptions.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.
InvalidImageContentException- The data of a glyph of the text is malformed.
UnsupportedImageFeatureException- The outlines of the font use a feature that is not supported.
ImageResourceLimitException- The text exceeds a limit of the configuration of the font, or 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 bars are one shape, painted with BarcodeDrawingOptions.DarkBrush. The text (Barcode.Text) is centered under the bars; a text wider than the barcode widens the drawing, and the barcode is centered above it. Use BarcodeImageRenderer.MeasureBarcode to know the size before drawing.
MeasureBarcode(Barcode, BarcodeDrawingOptions?)
BarcodeImageRenderer.csMeasures the rectangle that BarcodeImageRenderer.DrawBarcode covers, quiet zone and text included.
public static RectangleD MeasureBarcode(Barcode barcode, BarcodeDrawingOptions? options = null)Parameters
barcodeBarcode- The barcode to measure.
optionsBarcodeDrawingOptions?- The drawing options, or
nullfor the defaults.
Returns
RectangleD The size of the drawing, as a rectangle located at the origin.
Exceptions
ArgumentNullExceptionbarcodeisnull.ArgumentOutOfRangeException- An option is out of range.
InvalidImageContentException- The data of a glyph of the text is malformed.
UnsupportedImageFeatureException- The outlines of the font use a feature that is not supported.
ImageResourceLimitException- The text exceeds a limit of the configuration of the font.
ToImage(Barcode, BarcodeDrawingOptions?)
BarcodeImageRenderer.csRenders the barcode as an image: what BarcodeImageRenderer.DrawBarcode draws on a canvas of the size BarcodeImageRenderer.MeasureBarcode gives, rounded up.
public static Image<Rgba32> ToImage(this Barcode barcode, BarcodeDrawingOptions? options = null)Parameters
barcodeBarcode- The barcode to render.
optionsBarcodeDrawingOptions?- The drawing options, or
nullfor the defaults.
Returns
Image<Rgba32> A single-frame image. The caller owns it and must dispose it.
Exceptions
ArgumentNullExceptionbarcodeorBarcodeDrawingOptions.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 BarcodeDrawingOptions.SnapToPixels, the modules are whole pixels and the image has two colors when the brushes are solid. With a null BarcodeDrawingOptions.LightBrush, the background is transparent.