1
@Override
public String generateBrcodeForId(String Id) {
BarcodeUtil util = BarcodeUtil.getInstance();
BarcodeGenerator gen;
ByteArrayOutputStream byteArrayOutputStream = null;
try {
gen = util.createBarcodeGenerator(buildCfg("code128"));
OutputStream fout;
fout = new FileOutputStream("code128.jpg");
byteArrayOutputStream = new ByteArrayOutputStream();
int resolution = 200;
BitmapCanvasProvider canvas = new BitmapCanvasProvider(
fout, "image/jpeg", resolution, BufferedImage.TYPE_BYTE_BINARY, false, 0);
gen.generateBarcode(canvas, "12345678");
canvas.finish();
} catch (ConfigurationException | BarcodeException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
private static Configuration buildCfg(String type) {
DefaultConfiguration cfg = new DefaultConfiguration("barcode");
//Bar code type
DefaultConfiguration child = new DefaultConfiguration(type);
cfg.addChild(child);
//Human readable text position
DefaultConfiguration attr = new DefaultConfiguration("human-readable");
DefaultConfiguration subAttr = new DefaultConfiguration("placement");
subAttr.setValue("bottom");
attr.addChild(subAttr);
child.addChild(attr);
return cfg;
}
已經使用Barcode4j創建了一個條形碼,在這裏它創建了一個圖像code128.jpg。我可以創建一個字節數組,而不是在文件系統中創建映像並將其發送給Web服務客戶端。使用B4j創建一個字節數組條形碼