Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java中使用zxing从手持条形码扫描仪读取条形码_Java_Barcode_Zxing_Barcode Scanner_Barcode Printing - Fatal编程技术网

如何在Java中使用zxing从手持条形码扫描仪读取条形码

如何在Java中使用zxing从手持条形码扫描仪读取条形码,java,barcode,zxing,barcode-scanner,barcode-printing,Java,Barcode,Zxing,Barcode Scanner,Barcode Printing,我正在使用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

我正在使用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);
   }
}
包eg.com.taman.bc.tut;
导入com.google.zxing.BarcodeFormat;
导入com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
导入com.google.zxing.qrcode.decoder.Mode;
导入eg.com.tm.barcode.processor.barcode引擎;
导入eg.com.tm.barcode.processor.config.DecodeConfig;
导入eg.com.tm.barcode.processor.config.EncodeConfig;
导入java.io.File;
导入java.util.Map;
公共类条码应用程序{
公共静态void main(字符串[]args){
//文件将用于创建QRCode条形码类型。
File qrCodeFile=新文件(“C:\\barcode\\QRCode.png”);
//构建编码配置-使用builder battern
EncodeConfig EncodeConfig=
新建EncodeConfig.Builder().CreateDirectory(Boolean.TRUE)
.isQRCodeFormat(Boolean.TRUE)
.withErrorCorrLevel(ErrorCorrectionLevel.M).build();
//生成QRCode条码
String content=“这是条形码的内容。7654321(QRCode)”;
encode(qrCodeFile,content,BarcodeFormat.QR_CODE,200200,encodeConfig);
编码配置=
新建EncodeConfig.Builder().CreateDirectory(Boolean.TRUE)。
withCharactersMode(模式.字母数字).build();
System.out.println(“----------------------开始写入条形码-----------------\n”);
System.out.println(“是否创建了QRCode?”+(qrCodeFile.exists()?“是”:“未创建”)+“已创建”);
System.out.println(“\n-----------------已完成条形码的编写-----------------”;
//现在我们将解码(读取)已创建条形码的内容
//构建解码配置-使用builder battern
解码配置解码配置=
新建DecodeConfig.Builder()
.WithHumanBarcode(Boolean.TRUE)
.build();
Map results=BarcodeEngine.decode(qrCodeFile,decodeConfig);
字符串decodeText=(字符串)results.get(BarcodeEngine.DecodeResults.RESULT);
字符串barcodeType=((BarcodeFormat)results.get(BarcodeEngine.DecodeResults.BARCODE_FORMATE)).name();
System.out.println(“\n-----------------开始读取条形码-----------------\n”);
System.out.println(“解码内容为:\”“+decodeText+”\,条码类型为:“+barcodeType”);
System.out.println(“解码内容为:\”“+decodeText+”\,条码类型为:“+barcodeType”);
System.out.println(“\n-----------------已完成条形码的读取-----------------”;
System.out.println(“解码文本:+decodeText”);
System.out.println(“条形码类型:“+barcodeType”);
}
}
该代码将Qr条形码读取为图像文件。现在我想用手持式条形码扫描仪来读取条形码。有什么帮助吗?


我工作的是java桌面应用程序,不是Android

我的理解是,zxing用于生成和处理二维码图像。。。正如您在代码中所做的那样。它不是用于驱动条形码扫描仪的API。如果您想要其中一个,您需要说明您正在尝试使用的设备。

听起来您正在寻找支持HID模式的扫描仪

你的选择是一个或一个USB扫描仪(大多数像键盘一样)


一旦您选择了一个,HID模式在所有扫描仪上基本相同,您可以在Stackoverflow上找到许多关于捕获扫描仪输入并将其与普通键盘上的用户输入分离的问题。

我对其进行了一些研究,在大多数情况下,它工作正常。 我的代码是:

    InputStream barCodeInputStream = new FileInputStream("test.png");
    BufferedImage barCodeBufferedImage = ImageIO.read(barCodeInputStream);
    LuminanceSource source = new BufferedImageLuminanceSource(barCodeBufferedImage);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    Reader reader = new MultiFormatReader();
    Result result = reader.decode(bitmap);
    System.out.println("Barcode text is " + result.getText());

这对二维码和条形码都适用:)

我已经附上了我的代码,因此如果有任何不清楚的地方,请通知我。所以问题是“如何使用手持条形码扫描仪读取条形码?”是这样吗?你能解释一下你发布的代码与问题的相关性吗?在我看来,这与使用扫描仪读取二维码无关。我不知道要购买哪种设备,但我需要一种类似于编程键盘的设备。在您决定购买/使用哪种设备之前,我们无法建议您如何编程。你需要自己研究一下。关于选择硬件的建议是离题的。为什么设备很重要?假设整个事情都是关于图像的,那么我们所需要知道的就是生成图像的位置。如果它不写入文件系统,则必须以其他方式传输已知格式的图像。你能举一个设备的例子来说明需要知道将要使用的设备吗?是的,在maven项目中尝试,这样lib就会自动下载。