【发布时间】:2023-11-13 20:51:01
【问题描述】:
使用 zxing,我设法将 Code39 条形码保存为 PNG,但它只显示条形,没有数字。我怎么能在一个 PNG 中包含条形码和编号?
KI
【问题讨论】:
使用 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.
【讨论】: