【问题标题】:How to use Barcode4J to get the barcode number?如何使用 Barcode4J 获取条码号?
【发布时间】:2013-08-01 06:45:14
【问题描述】:

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

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

下面是如何生成条形码图像的代码sn-p。

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

【问题讨论】:

    标签: java web barcode barcode4j


    【解决方案1】:

    上面的sn-p告诉barcode4j进行编码,渲染为位图并写入outputFile字符串storeNumber + orderId,所以请求的服务只需要

    return (storeNumber + orderId);
    

    如果您需要解码仅给出outputFile 的条形码,请查看ZXing 项目。

    【讨论】:

    • 不,我使用的是 EAN13。我确定最后有一个随机校验位。
    【解决方案2】:

    由于您现有的方法有效,只需创建新方法并传递 (storeNumber + orderId) 作为方法参数。

    *Existing method...*
    String barText=storeNumber + orderId;
    getBarcodeText(barText);
    
    public String getBarcodeText(String barText) {
    
        <other checking>
        return barText;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-16
      • 2014-06-05
      • 2014-01-06
      • 2014-03-29
      • 1970-01-01
      • 2012-11-16
      • 1970-01-01
      • 2011-05-07
      相关资源
      最近更新 更多