QrImage constructor

QrImage(
  1. QrCode qrCode
)

Generates a QrImage with the best mask pattern encoding qrCode.

Implementation

factory QrImage(QrCode qrCode) {
  var minLostPoint = 0.0;
  QrImage? bestImage;

  for (var i = 0; i < 8; i++) {
    final testImage = QrImage._test(qrCode, i);
    final lostPoint = _lostPoint(testImage);

    if (i == 0 || minLostPoint > lostPoint) {
      minLostPoint = lostPoint;
      bestImage = testImage;
    }
  }

  return QrImage.withMaskPattern(qrCode, bestImage!.maskPattern);
}