fileToImage method

FlipperImage fileToImage(
  1. File file
)

Implementation

FlipperImage fileToImage(File file) {
  final bytes = file.readAsBytesSync();
  final decoder = _decoderFor(bytes);
  final decoded = decoder == null
      ? img.decodeImage(bytes)
      : decoder.decode(bytes);
  if (decoded == null) {
    throw FormatException('Failed to decode image ${file.path}');
  }
  // Netpbm bitmaps store 1 as black, PnmDecoder hands it back as white while
  // PIL, which fbt builds with, keeps it black.
  if (_isPbm(bytes)) img.invert(decoded);
  return toImage(decoded);
}