【发布时间】:2013-10-13 01:31:41
【问题描述】:
我在 java 中使用名为“zxing”(斑马线)的开源 Java 库。我的代码在这里
package eg.com.taman.bc.tut;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.google.zxing.qrcode.decoder.Mode;
import eg.com.tm.barcode.processor.BarcodeEngine;
import eg.com.tm.barcode.processor.config.DecodeConfig;
import eg.com.tm.barcode.processor.config.EncodeConfig;
import java.io.File;
import java.util.Map;
public class BarcodeApplication {
public static void main(String[] args) {
// File will be used for creating the QRCode barcode type.
File qrCodeFile = new File("C:\\barcode\\QRCode.png");
// Building the encoding configurations - using builder battern
EncodeConfig encodeConfig =
new EncodeConfig.Builder().createDirectories(Boolean.TRUE)
.isQRCodeFormat(Boolean.TRUE)
.withErrorCorrLevel(ErrorCorrectionLevel.M).build();
// Generating the QRCode barcode
String content = "This is the contents of the barcode. 7654321 (QRCode)";
BarcodeEngine.encode(qrCodeFile, content, BarcodeFormat.QR_CODE, 200, 200, encodeConfig);
encodeConfig =
new EncodeConfig.Builder().createDirectories(Boolean.TRUE).
withCharactersMode(Mode.ALPHANUMERIC).build();
System.out.println("------------------- Begins Writing barcodes -------------------\n");
System.out.println("Is QRCode Created? " + (qrCodeFile.exists() ? "Yes " : "Not not ") + "Created");
System.out.println("\n------------------- Finished Writing barcodes -------------------");
// Now we are going to decode (read) back contents of created barcodes
// Building the decoding configurations - using builder battern
DecodeConfig decodeConfig =
new DecodeConfig.Builder()
.withHumanBarcodes(Boolean.TRUE)
.build();
Map<BarcodeEngine.DecodeResults, Object> results = BarcodeEngine.decode(qrCodeFile, decodeConfig);
String decodeText = (String) results.get(BarcodeEngine.DecodeResults.RESULT);
String barcodeType = ((BarcodeFormat) results.get(BarcodeEngine.DecodeResults.BARCODE_FORMATE)).name();
System.out.println("\n------------------- Begins reading barcodes -------------------\n");
System.out.println("The decoded contents is: \"" + decodeText + "\", Barcode type is: " + barcodeType);
System.out.println("The decoded contents is: \"" + decodeText + "\", Barcode type is: " + barcodeType);
System.out.println("\n------------------- Finished reading barcodes -------------------");
System.out.println("decode Text : "+decodeText);
System.out.println("barcode Type : "+barcodeType);
}
}
代码将 Qr 条码读取为图像文件。现在我想使用手持条码扫描仪来读取条码。有什么帮助吗??????
我正在使用 Java 桌面应用程序而不是 Android。
【问题讨论】:
-
我已经附上了我的代码,所以如果有什么不清楚的地方请告诉我。
-
那么问题是“手持条码扫描器是如何读取条码的?”是这样吗?
-
您能否解释一下您发布的代码与问题的相关性?在我看来,这与使用扫描仪读取二维码无关。
标签: java barcode zxing barcode-scanner barcode-printing