繁体   English   中英

如何使用Barcode4J获取条形码编号?

[英]How to use Barcode4J to get the barcode number?

我正在使用条形码4j生成一些条形码图像,效果很好。

但是UI团队希望我出于某种奇怪的原因为他们编写一些服务以返回String的条形码编号。 我不知道该怎么做。

以下是如何生成条形码图像的代码段。

final File outputFile = new File(folderPath + "/" + TgtCoreConstants.TARGET_BARCODE_FILE_PREFIX
            + orderId + BARCODE_FILENAME_EXTENSION);
    OutputStream out = null;
    try {
        out = new FileOutputStream(outputFile);
        final BitmapCanvasProvider canvas = new BitmapCanvasProvider(
                out, BARCODE_MIME_TYPE, cncBarcodeDpi, BufferedImage.TYPE_BYTE_BINARY, false, 0);
        bean.generateBarcode(canvas, (storeNumber + orderId));
        canvas.finish();
    }
    catch (final FileNotFoundException e) {
        LOG.error("Error while generating the barcode file for order: " + orderId, e);
        throw new GenerateBarCodeFailedException(e);
    }
    catch (final IOException e) {
        LOG.error("Error while generating the barcode file for order: " + orderId, e);
        throw new GenerateBarCodeFailedException(e);
    }

上面的代码片段告诉条形码4j进行编码,渲染为位图,并在字符串storeNumber + orderId字符串storeNumber + orderId写入outputFile ,因此所请求的服务只需要

return (storeNumber + orderId);

如果只需要解码outputFile给出的条形码,则查看ZXing项目。

由于您现有的方法有效,因此只需创建新方法并通过(storeNumber + orderId)作为方法参数即可。

*Existing method...*
String barText=storeNumber + orderId;
getBarcodeText(barText);

public String getBarcodeText(String barText) {

    <other checking>
    return barText;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM