loadImageBytes method
Loads the asset PNG and converts it into bytes suitable for Mapbox markers.
The image will be automatically optimized for display on the map.
Returns null if the asset cannot be loaded.
Implementation
Future<Uint8List?> loadImageBytes() async {
try {
final data = await rootBundle.load(assetPath);
final codec = await ui.instantiateImageCodec(
data.buffer.asUint8List(),
targetWidth: 64,
targetHeight: 64,
);
final frame = await codec.getNextFrame();
final byteData = await frame.image.toByteData(format: ui.ImageByteFormat.png);
return byteData?.buffer.asUint8List();
} catch (e) {
debugPrint('Error loading asset $assetPath: $e');
return null;
}
}