QRImage constructor

QRImage(
  1. QRCodeGenerate qrCode
)

Generates a QrImage with the best mask pattern encoding qrCode.

Implementation

factory QRImage(QRCodeGenerate 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);
}