decode method

  1. @override
Result decode(
  1. BinaryBitmap image, {
  2. DecodeHints? hints,
})
override

Locates and decodes a QR code in an image.

@return a String representing the content encoded by the QR code @throws NotFoundException if a QR code cannot be found @throws FormatReaderException if a QR code cannot be decoded @throws ChecksumException if error correction fails

Implementation

@override
Result decode(BinaryBitmap image, {DecodeHints? hints}) {
  hints ??= DecodeHints();
  DecoderResult decoderResult;
  List<ResultPoint> points;
  if (hints.contains(DecodeHintType.pureBarcode)) {
    var bits = _extractPureBits(image.getBlackMatrix());
    decoderResult = decoder.decode(bits, hints: hints);
    points = _kNoPoints;
  } else {
    var detectorResult =
        Detector(image.getBlackMatrix()).detect(hints: hints);
    decoderResult = decoder.decode(detectorResult.bits, hints: hints);
    points = detectorResult.points;
  }

  // If the code was mirrored: swap the bottom-left and the top-right points.
  var other = decoderResult.other;
  if (other is QRCodeDecoderMetaData) {
    other.applyMirroredCorrection(points);
  }

  var result = Result(
      decoderResult.text, decoderResult.rawBytes, BarcodeFormat.qrCode,
      points: points);
  var byteSegments = decoderResult.byteSegments;
  if (byteSegments != null) {
    result.putMetadata(ResultMetadataType.byteSegments, byteSegments);
  }
  var ecLevel = decoderResult.ecLevel;
  if (ecLevel != null) {
    result.putMetadata(ResultMetadataType.errorCorrectionLevel, ecLevel);
  }
  if (decoderResult.hasStructuredAppend) {
    result.putMetadata(ResultMetadataType.structuredAppendSequence,
        decoderResult.structuredAppendSequenceNumber);
    result.putMetadata(ResultMetadataType.structuredAppendParity,
        decoderResult.structuredAppendParity);
  }
  return result;
}