Class CanvasBarcodeExtensions
Draws barcodes on any Canvas: rasters, PDF and SVG pages, recordings.
public static class CanvasBarcodeExtensions
- Inheritance
-
CanvasBarcodeExtensions
- Inherited Members
Examples
using Raster<Rgba8> label = Raster.Create(300, 200, Rgba8.White);
using (RasterCanvas<Rgba8> canvas = label.CreateCanvas())
{
// Fitted into the rectangle and centered, quiet zone inside it; on a raster, modules snap to whole pixels.
canvas.DrawBarcode(qr, new RectF(20, 20, 160, 160), Rgba8.Black);
}
Methods
DrawBarcode(Canvas, Barcode, RectF, Paint, BarcodeDrawOptions?)
Draws a barcode fitted into a rectangle and centered in it, as one filled path, with its quiet zone kept clear inside the rectangle. 2D symbols keep square modules; linear bars fill the rectangle's height, less the text line. On a raster canvas with no rotation or skew, modules snap to whole pixels (as large as still fit), so edges stay sharp.
public static void DrawBarcode(this Canvas canvas, Barcode barcode, RectF rect, Paint paint, BarcodeDrawOptions? options = null)
Parameters
canvasCanvasThe canvas.
barcodeBarcodeThe barcode.
rectRectFThe rectangle, in local coordinates.
paintPaintThe paint for the bars and the text.
optionsBarcodeDrawOptionsThe quiet zone, bar width reduction and font, or null for Default.
Examples
using Raster<Rgba8> label = Raster.Create(300, 200, Rgba8.White);
using (RasterCanvas<Rgba8> canvas = label.CreateCanvas())
{
// Fitted into the rectangle and centered, quiet zone inside it; on a raster, modules snap to whole pixels.
canvas.DrawBarcode(qr, new RectF(20, 20, 160, 160), Rgba8.Black);
}
DrawBarcode(Canvas, Barcode, Vector2, float, Paint, BarcodeDrawOptions?)
Draws a barcode at a given module size, with the top-left corner of its quiet zone at a point. Linear bars are Height modules tall. On a raster canvas with no rotation or skew, the module size rounds to whole pixels and the symbol to the pixel grid, so edges stay sharp.
public static void DrawBarcode(this Canvas canvas, Barcode barcode, Vector2 origin, float moduleSize, Paint paint, BarcodeDrawOptions? options = null)
Parameters
canvasCanvasThe canvas.
barcodeBarcodeThe barcode.
originVector2The top-left corner of the quiet zone, in local coordinates.
moduleSizefloatThe width of a module in local units, the X dimension of the standards.
paintPaintThe paint for the bars and the text.
optionsBarcodeDrawOptionsThe quiet zone, bar width reduction and font, or null for Default.
Examples
// A 0.33 mm module (the X dimension) in points, with the text under the bars and 0.05 mm taken off each bar
// for ink spread. The quiet zone's top-left corner goes at (36, 36).
float module = 0.33f / 25.4f * 72;
page.DrawBarcode(code, new Vector2(36, 36), module, Rgba8.Black, new BarcodeDrawOptions
{
Font = font,
BarWidthReduction = 0.05f / 25.4f * 72,
});
Exceptions
- ArgumentOutOfRangeException
moduleSizeis not positive and finite.