TBarCode .NET 常见问题
如何以 4 位/像素格式保存条码?
如何以 4 位/像素格式保存条码?
首先以默认的像素格式(Format32bppArgb)生成条码:
System.Drawing.Size optimalSize = myBarcode.CalculateOptimalBitmapSize(null, 2, 2); myBarcode.BoundingRectangle = new Rectangle(0, 0, optimalSize.Width, optimalSize.Height); Bitmap barcodeImage = myBarcode.DrawBitmap();
然后将其转换为您所需像素格式的位图:
Bitmap converted = barcodeImage.Clone (new Rectangle(0, 0, barcodeImage.Width, barcodeImage.Height), PixelFormat.Format4bppIndexed); // MessageBox.Show(converted.PixelFormat.ToString());
即使您为二进制数据使用转义序列,编码器仍会执行代码页转换(例如:\x88 在 Data Matrix 中会得到与预期不同的值)。
解决方案:
- 关闭代码页转换(使用 LowByte 编码模式)
- 如果可用,强制使用二进制编码模式(参见 PDF417 的编码模式、Data Matrix 的 EnforceBinaryEncoding)
此内容适用于 DP Premium Address 以及其他需要在二维符号(Data Matrix 等)中编码二进制数据的应用场景。