loadBmpImage function

Future<MemoryImage> loadBmpImage(
  1. String path
)

Implementation

Future<MemoryImage> loadBmpImage(String path) async {
  try {
    print('[BMP Image]');
    // Load BMP file data from assets
    final data = await rootBundle.load(path);
    print(data);
    final bytes = data.buffer.asUint8List();

    // Decode BMP image to Image using the image package
    final img.Image? decodedImage = img.decodeBmp(bytes);

    // Convert decoded Image to a format that Flutter can display
    if (decodedImage != null) {
      final List<int> pngBytes = img.encodePng(decodedImage);
      return MemoryImage(Uint8List.fromList(pngBytes));
    } else {
      throw Exception('Failed to decode BMP image');
    }
  } catch (e) {
    print(e.toString());
    return MemoryImage(Uint8List.fromList([])); // Return
  }
}