Barcode2DImageRenderer Class
Provides methods to render a two-dimensional barcode as an Image<TPixel>.
public static class Barcode2DImageRendererMethods
| Name | Description |
|---|---|
| DrawBarcode2D(DrawingCanvas, Barcode2D, PointD, Barcode2DDrawingOptions?) | Draws the barcode on a canvas, as a vector shape. |
| MeasureBarcode2D(Barcode2D, Barcode2DDrawingOptions?) | Measures the rectangle that Barcode2DImageRenderer.DrawBarcode2D covers, quiet zone included. |
| ToImage(Barcode2D, Barcode2DDrawingOptions?) | Renders the barcode as an image: what Barcode2DImageRenderer.DrawBarcode2D draws on a canvas of the size Barcode2DImageRenderer.MeasureBarcode2D gives, rounded up. |
DrawBarcode2D(DrawingCanvas, Barcode2D, PointD, Barcode2DDrawingOptions?)
Barcode2DImageRenderer.csDraws the barcode on a canvas, as a vector shape.
public static RectangleD DrawBarcode2D(this DrawingCanvas canvas, Barcode2D barcode, PointD position, Barcode2DDrawingOptions? options = null)Parameters
canvasDrawingCanvas- The canvas to draw on.
barcodeBarcode2D- The barcode to draw.
positionPointD- The top-left corner of the quiet zone. It is rounded to whole units when
Barcode2DDrawingOptions.SnapToPixelsis set. optionsBarcode2DDrawingOptions?- The drawing options, or
nullfor the defaults.
Returns
RectangleD The rectangle the drawing covers, quiet zone included.
Exceptions
ArgumentNullExceptionbarcodeorBarcode2DDrawingOptions.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 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 Barcode2DDrawingOptions.DarkBrush, so adjacent modules have no seam. Use Barcode2DImageRenderer.MeasureBarcode2D to know the size before drawing.
MeasureBarcode2D(Barcode2D, Barcode2DDrawingOptions?)
Barcode2DImageRenderer.csMeasures the rectangle that Barcode2DImageRenderer.DrawBarcode2D covers, quiet zone included.
public static RectangleD MeasureBarcode2D(Barcode2D barcode, Barcode2DDrawingOptions? options = null)Parameters
barcodeBarcode2D- The barcode to measure.
optionsBarcode2DDrawingOptions?- 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.
ToImage(Barcode2D, Barcode2DDrawingOptions?)
Barcode2DImageRenderer.csRenders the barcode as an image: what Barcode2DImageRenderer.DrawBarcode2D draws on a canvas of the size Barcode2DImageRenderer.MeasureBarcode2D gives, rounded up.
public static Image<Rgba32> ToImage(this Barcode2D barcode, Barcode2DDrawingOptions? options = null)Parameters
barcodeBarcode2D- The barcode to render.
optionsBarcode2DDrawingOptions?- The drawing options, or
nullfor the defaults.
Returns
Image<Rgba32> A single-frame image. The caller owns it and must dispose it.
Exceptions
ArgumentNullExceptionbarcodeorBarcode2DDrawingOptions.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 Barcode2DDrawingOptions.SnapToPixels, the modules are whole pixels and the image has two colors when the brushes are solid. With a null Barcode2DDrawingOptions.LightBrush, the background is transparent.