Preguntas frecuentes sobre TBarCode .NET
¿Cómo puedo crear un mapa de bits PDF417 legible con tamaño constante?
¿Cómo puedo crear un mapa de bits PDF417 legible con tamaño constante?
El siguiente código de ejemplo en C# ASP.NET genera una imagen PDF417 con tamaño constante.
//PDF417 Barcode barcode = new Barcode(); barcode.Data = strMyData; barcode.BarcodeType = BarcodeType.Pdf417; barcode.Pdf417.EncodingMode = PdfEncodingMode.Binary; // with dpi = 100 we get 1 Pixel = 0.254 mms barcode.Dpi = 100; // we should specify the number of horizontal data columns // this inhibits the symbol to change its horizontal size regardless of data barcode.Pdf417.NumberOfColumns = 16; // use a value, which fits to your available space !! // now calculate optimal bitmap size for the bar code barcode.SizeMode = SizeMode.FitToBoundingRectangle; Size optimalSize = barcode.CalculateOptimalBitmapSize(null, 1, 1); // we already could use this optimal Size for saving the image // barcode.BoundingRectangle = new Rectangle(0, 0, optimalSize.Width, optimalSize.Height); // barcode.Draw(filename, ImageType.Jpg); // but we want a constant bitmap size, // which fits exactly into your predefined space Size finalSize = new Size(350, 200); // final bitmap size in Pixel // so we have to add empty spaces around the symbol via adding a quiet zone barcode.QuietZoneUnit = QuietZoneUnit.Pixel; // calculate the required empty quiet zone we have to add if (finalSize.Width > optimalSize.Width) barcode.QuietZoneRight = finalSize.Width - optimalSize.Width; else // should not occur!! Reduce the Pdf417.NumberOfColumns finalSize.Width = optimalSize.Width; if (finalSize.Height > optimalSize.Height) barcode.QuietZoneBottom = finalSize.Height - optimalSize.Height; else // should not occur!! Increase final bitmap size finalSize.Height = optimalSize.Height; barcode.BoundingRectangle = new Rectangle(0, 0, finalSize.Width, finalSize.Height); barcode.Draw(filename, ImageType.Jpg);