FAQ TBarCode .NET
Come posso creare una bitmap ITF-14 ottimizzata per stampanti termiche?
Come posso creare una bitmap ITF-14 ottimizzata per stampanti termiche?
Il seguente codice di esempio in C# .NET genera un'immagine di codice a barre ottimizzata per l'output di stampanti termiche (risoluzioni come 203 dpi).
// Create an ITF-14 bar code for a label to be printed with 203 dpi
// Bearer bar width = 2 X (X = module width)
// We fine-tune the module width using AdjustModuleWidthToPixelRaster.
Barcode code = new Barcode ();
code.BarcodeType = TECIT.TBarCode.BarcodeType.ITF14;
code.Data = "1234567890123";
code.Font = new System.Drawing.Font("Arial", 15, System.Drawing.FontStyle.Bold, GraphicsUnit.Point);
code.TextDistance = 1.1F; // mm
// important: set printer resolution of thermal printer
code.Dpi = 203;
// 203 dpi --> Module Width = 0.5005 = 4 Pixel per Module
float moduleWidth = 0.5004926F; // use exact value!
code.SizeMode = TECIT.TBarCode.SizeMode.CustomModuleWidth;
code.ModuleWidth = moduleWidth + 0.001; // add delta to extend optimization range
code.AdjustModuleWidthToPixelRaster = true;
double modulesBearerBar = 2; // 2 X
code.BearerBarType = TECIT.TBarCode.BearerBarType.TopAndBottom;
code.BearerBarWidth = moduleWidth * modulesBearerBar;
// adjust quiet zone in [Modules] (recommended for bitmaps)
code.QuietZones.Unit = TECIT.TBarCode.QuietZoneUnit.Modules;
code.QuietZones.Left.Size = 10F;
code.QuietZones.Right.Size = 10F;
// for rectangular bearer bar having a width of 4.83 mm
// code.BearerBarWidth = 4.83F;
// double modulesBearerBar = Math.Round(code.BearerBarWidth / moduleWidth, MidpointRounding.AwayFromZero);
// code.QuietZones.Left.Size = 10F + modulesBearerBar;
// code.QuietZones.Right.Size = 10F + modulesBearerBar;
// size in [mm]
double width = code.CalculateBarcodeWidth(null);
double height = 35;
// convert size to [Pixels]
width = width / (25.4 / code.Dpi);
height = height / (25.4 / code.Dpi);
// adjust bitmap size
code.BoundingRectangleF = new RectangleF(0, 0, (float) width, (float) height);
// output to file
code.Draw("barcode-ITF-14-203dpi.bmp", TECIT.TBarCode.ImageType.Bmp);