我想写一个Java代码来生成条形码在三行。下面的代码在一行中创建了一个条形码。如果你对此有任何解决方案,这将是非常有帮助的。
Barcode barcode = BarcodeFactory.createCode128(codeValue);
barcode.setDrawingText(false);
barcode.setBarHeight(200);
barcode.setBarWidth(5);
BufferedImage image = new BufferedImage(500, 500,
BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g = (Graphics2D) image.getGraphics();
barcode.draw(g, 6, 30);在此之后,我为条形码创建了一个图像。
File f = new File("Path\\Bar_Img.jpeg");
FileOutputStream fileOutputStream = new FileOutputStream(f);
// Let the barcode image handler do the hard work
BarcodeImageHandler.writeJPEG(barcode, fileOutputStream);因此这将创建一个单行条形码。但是我想创建一个带有三行条形码的图像

发布于 2018-01-29 19:44:36
我不确定codeValue的类型是什么,但也许可以试着将包含不同值的数组放入for循环中,如下所示。
String codeValue[] = new String[3];
codeValue[0] = "Some text";
codeValue[1] = "Some text";
codeValue[2] = "Some text";
for (i = 0; i < codeValue.length; i++) {
Barcode barcode = BarcodeFactory.createCode128(codeValue[i]);
barcode.setDrawingText(false);
barcode.setBarHeight(200);
barcode.setBarWidth(5);
BufferedImage image = new BufferedImage(500, 500,
BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g = (Graphics2D) image.getGraphics();
barcode.draw(g, 6, 30);
}
System.out.println("Loop over");https://stackoverflow.com/questions/48499938
复制相似问题