Example #1
0
  // YUVオブジェクトのバイナリデータを読み込み、マーカーを検知
  public void readYUV(
      final byte[] data,
      int dataWidth,
      int dataHeight,
      int left,
      int top,
      int width,
      int height,
      boolean reserversion) {
    final LuminanceSource source =
        new PlanarYUVLuminanceSource(
            data, dataWidth, dataHeight, left, top, width, height, reserversion);

    final BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
    // final Reader reader = new MultiFormatReader();
    final Reader reader = new QRCodeReader();
    try {
      // 結果をゲット
      mQRResult.setResultData(reader.decode(binaryBitmap));
      mFoundFlag = true;
    }
    // 見つからなかった!
    catch (NotFoundException ex) {
      ex.printStackTrace();
      mFoundFlag = false;
    } catch (ChecksumException ex) {
      ex.printStackTrace();
      mFoundFlag = false;
    } catch (FormatException ex) {
      ex.printStackTrace();
      mFoundFlag = false;
    }
  }
  // Called when camera take a frame
  @Override
  public void onPreviewFrame(byte[] data, Camera camera) {

    PlanarYUVLuminanceSource source =
        mCameraManager.buildLuminanceSource(data, mPreviewWidth, mPreviewHeight);

    HybridBinarizer hybBin = new HybridBinarizer(source);
    BinaryBitmap bitmap = new BinaryBitmap(hybBin);

    try {
      Result result = mQRCodeReader.decode(bitmap);

      // Notify We're found a QRCode
      if (mOnQRCodeReadListener != null) {
        // Transform resultPoints to View coordinates
        PointF[] transformedPoints = transformToViewCoordinates(result.getResultPoints());
        mOnQRCodeReadListener.onQRCodeRead(result.getText(), transformedPoints);
      }

    } catch (ChecksumException e) {
      Log.d(TAG, "ChecksumException");
      e.printStackTrace();
    } catch (NotFoundException e) {
      // Notify QR not found
      if (mOnQRCodeReadListener != null) {
        mOnQRCodeReadListener.QRCodeNotFoundOnCamImage();
      }
    } catch (FormatException e) {
      Log.d(TAG, "FormatException");
      e.printStackTrace();
    } finally {
      mQRCodeReader.reset();
    }
  }