我遇到了两个内容相同但原始字节不同的条形码之间的差异.一个条形码是使用一个名为Labelary的在线工具生成的,该工具用于创建ZPL标签,另一个条形码是在我的Java代码中使用ZXing库生成的.尽管具有相同的内容,但条形码的视觉外观不同.
My Barcode
Raw text: 12345678
Raw bytes: 69 0c 22 38 4e 2f 6a
BarcodeGenerator.java
个
public byte[] getBarCode128(String data, int width, int height) {
Code128Writer writer = new Code128Writer();
BitMatrix matrix = writer.encode(data, BarcodeFormat.CODE_128, width, height);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
MatrixToImageWriter.writeToStream(matrix, "png", outputStream);
return outputStream.toByteArray();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
Main.java
个
public static void main(String[] args) {
String data = "12345678";
int width = (int) (data.length() * 11 * moduleWidth);
int height = 270;
BarcodeGenerator barcode = new BarcodeGenerator();
byte[] barcodeImageBytes = barcode.getBarCode128(data, (int) width, (int) height);
}
Barcode from Labelary
点击here查看源代码.
Raw text: 12345678
Raw bytes: 68 11 12 13 14 15 16 17 18 3c 6a
造成这种差异的潜在原因是什么?如何使用Java中的ZXing库确保正确的条形码生成?