FAQ TBarCode .NET
How to Save the Barcode in 4 Bit/Pixel Format?
How to Save the Barcode in 4 Bit/Pixel Format?
First generate the barcode in the default Pixel format (Format32bppArgb):
System.Drawing.Size optimalSize = myBarcode.CalculateOptimalBitmapSize(null, 2, 2); myBarcode.BoundingRectangle = new Rectangle(0, 0, optimalSize.Width, optimalSize.Height); Bitmap barcodeImage = myBarcode.DrawBitmap();
Then convert it to a bitmap with the Pixel format you need:
Bitmap converted = barcodeImage.Clone (new Rectangle(0, 0, barcodeImage.Width, barcodeImage.Height), PixelFormat.Format4bppIndexed); // MessageBox.Show(converted.PixelFormat.ToString());
Even if you use an escape sequence for binary data the encoder will use code page conversion (example: \x88 leads to a different value in Data Matrix as desired).
Solution:
- Switch off code page conversion (use encoding mode LowByte)
- Force binary encoding mode if available (see PDF417 encoding mode, Data Matrix EnforceBinaryEncoding)
Relevant for DP Premium Address and other applications where you encode binary data in a 2D symbol (Data Matrix etc).