【问题标题】:Java code to create an image containing three code128 barcodes用于创建包含三个 code128 条形码的图像的 Java 代码
【发布时间】:2018-07-08 01:41:32
【问题描述】:

我想编写一个 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);

所以这将创建一个单行条形码。但我想用三行条形码创建一个图像

【问题讨论】:

  • 需要三个 codeValues,打印条形码。

标签: java image barcode multiline


【解决方案1】:

我不确定 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");

【讨论】:

  • 是的,但我想将三个条形码打印成单个图像。文件 f = new File("H:\\My Documents\\Tes_Bar\\Bar_Img.jpeg"); FileOutputStream fileOutputStream = new FileOutputStream(f); BarcodeImageHandler.writeJPEG(barcode, fileOutputStream);
  • 嗯..也许尝试将这些图像组合成更大的图像?
猜你喜欢
  • 2019-03-13
  • 2020-06-06
  • 2021-04-04
  • 2012-10-23
  • 1970-01-01
  • 2011-04-04
  • 1970-01-01
  • 2015-04-26
  • 1970-01-01
相关资源
最近更新 更多