我正在使用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);
}发布于 2013-08-02 16:26:12
上面的代码片段告诉barcode4j进行编码、呈现为位图并在outputFile中写入字符串storeNumber + orderId,因此请求的服务只需
return (storeNumber + orderId);如果您只需要解码给定的outputFile条形码,那么可以查看ZXing项目。
发布于 2017-07-19 16:37:35
由于您现有的方法正在运行,因此只需创建新方法&传递(storeNumber + orderId)作为方法参数。
*Existing method...*
String barText=storeNumber + orderId;
getBarcodeText(barText);
public String getBarcodeText(String barText) {
<other checking>
return barText;
}https://stackoverflow.com/questions/17986957
复制相似问题