ZXing 生成 UPC-A 条码的方法

可以使用下面的方法生成 UPC-A 条码

[code]Writer writer = new MultiFormatWriter();
BitMatrix bitMatrix = null;
byte pngData = null;

	try {
		bitMatrix = writer.encode(text, BarcodeFormat.UPC_A, this.width, this.height);

	} catch (WriterException we) {
		logger.error("Error: {}", we);
		return Action.ERROR;
	}

	ByteArrayOutputStream pngOut = new ByteArrayOutputStream();
	MatrixToImageWriter.writeToStream(bitMatrix, "PNG", pngOut);
	pngData = pngOut.toByteArray();[/code]

最重要的方法是:

bitMatrix = writer.encode(text, BarcodeFormat.UPC_A, this.width, this.height);

这个将输入的字符串 转换为 BitMatrix ,这个 BitMatrix 可以转换 byte 数据。