首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于创建包含三个code128条形码的图像的Java代码

用于创建包含三个code128条形码的图像的Java代码
EN

Stack Overflow用户
提问于 2018-01-29 19:13:46
回答 1查看 974关注 0票数 3

我想写一个Java代码来生成条形码在三行。下面的代码在一行中创建了一个条形码。如果你对此有任何解决方案,这将是非常有帮助的。

代码语言:javascript
复制
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);

在此之后,我为条形码创建了一个图像。

代码语言:javascript
复制
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);

因此这将创建一个单行条形码。但是我想创建一个带有三行条形码的图像

EN

回答 1

Stack Overflow用户

发布于 2018-01-29 19:44:36

我不确定codeValue的类型是什么,但也许可以试着将包含不同值的数组放入for循环中,如下所示。

代码语言:javascript
复制
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");
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48499938

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档