zxing - 导出带有编码值的 PNG 条码
zxing - export PNG barcode with encoded value
使用 zxing,我设法将 Code39 条形码保存为 PNG,但它只显示条形,不显示数字。我怎么能在单个 PNG 中包含条形码和编号?
基
您不能使用 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.
使用 zxing,我设法将 Code39 条形码保存为 PNG,但它只显示条形,不显示数字。我怎么能在单个 PNG 中包含条形码和编号?
基
您不能使用 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.