簡體   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