使用 zxing,我设法将 Code39 条形码保存为 PNG,但它只显示条形,没有数字。我怎样才能在一个 PNG 中包含条形码和编号?
KI
最佳答案
您无法使用 zxing 添加号码。您可以做一些事情,例如自己将文本添加到图像中,但这可能无法在所有情况下完美地工作,而不需要摆弄。
public static void main(String[] args) throws Exception {
final BufferedImage image = ...
Graphics g = image.getGraphics();
g.setFont(g.getFont().deriveFont(20f)); // select compatible font
g.drawString("numbers", 100, 100); // center on your image using image size
g.dispose();
ImageIO.write(image, "png", new File("barcode.png"));
}
或者,您可以将所有这些组织在 JPanel 中,然后将面板渲染为图像。这将使您受益于布局方向和配件。 Using something like this.
关于java - zxing - 导出带有编码值的 PNG 条形码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44389771/