couldBeQRCodeBMPWithHiddenTransparency function

bool couldBeQRCodeBMPWithHiddenTransparency(
  1. Uint8List bytes
)

Whether bytes is a BMP image of a perfect QR code with hidden transparency

When a PNG with transparency is copied to the Windows clipboard, it is converted to a Device Independent Bitmap with a BITMAPINFOHEADER and 32 bits per pixel. According to the spec a bitmap (BMP) with that header does not support transparency. However, since each pixel has 32 bits but only 8 bits per color there are 8 free bits in which windows writes the alpha value. BmpDecoder ignores that value therefore the decoded image has only black pixels. See: https://stackoverflow.com/questions/44287407/text-erased-from-screenshot-after-using-clipboard-getimage-on-windows-10/46400011#46400011

Implementation

bool couldBeQRCodeBMPWithHiddenTransparency(Uint8List bytes) {
  final bmpDecoder = BmpDecoder();
  if (!bmpDecoder.isValidFile(bytes)) {
    return false;
  }
  Image? img = bmpDecoder.decode(bytes);
  if (img == null) {
    return false;
  }
  return img.every((pixel) => pixel.r == 0 && pixel.g == 0 && pixel.b == 0);
}