1

Java で '<strong>zxing' (Zebra Crossing) と呼ばれるオープン ソースの 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 バーコードを画像ファイルとして読み取ります。今、私はバーコードを読み取るためにハンドヘルドバーコードスキャナーを使用したいと考えています。何か助けて?????

AndroidではなくJavaデスクトップアプリケーションで作業しています。

4

3 に答える 3

1

私の理解では、コードで行っているように、zxing は QR コード画像を生成および処理するためのものです。バーコード スキャナを駆動するための API ではありません。それらのいずれかが必要な場合は、使用しようとしているデバイスについて何かを言う必要があります.

于 2013-10-06T12:27:03.383 に答える
1

私はそれに少し取り組みましたが、ほとんどの場合、うまく機能しています。私のコードは次のとおりです。

    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());

これはQRとバーコードでうまく機能します:)

于 2016-05-31T12:06:18.457 に答える