2013-08-01 37 views
0

我正在使用barcode4j生成一些條形碼圖像,這很好。如何使用Barcode4J獲取條形碼號碼?

但是UI團隊想讓我寫一些服務來返回字符串中的條形碼號碼,這是因爲一些奇怪的原因。我無法弄清楚如何做到這一點。

下面是如何生成條碼圖像的代碼片段。

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); 
    } 

回答

0

上面的代碼告訴barcode4j編碼,渲染爲位圖和outputFilestoreNumber + orderId寫的,所以請求的服務需求只是

return (storeNumber + orderId); 

如果需要只給定條碼解碼outputFile,然後看看ZXing項目。

+0

不,我使用EAN13。我確信最後有一個隨機checkdigit。 – Seabook

0

由於您現有的方法正在工作,只需創建新方法&通過(storeNumber + orderId)作爲方法參數。

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

public String getBarcodeText(String barText) { 

    <other checking> 
    return barText; 
} 
相關問題