loadImageAsset function
Loads and decodes an image asset for sampler uniforms.
Implementation
Future<ImageLoadResult> loadImageAsset(String assetPath) async {
try {
final ByteData data = await rootBundle.load(assetPath);
final Uint8List bytes = data.buffer.asUint8List();
final codec = await ui.instantiateImageCodec(bytes);
final frame = await codec.getNextFrame();
return ImageLoadResult(image: frame.image);
} on FlutterError catch (e, stack) {
debugPrint('loadImageAsset error: $assetPath: $e');
return ImageLoadResult(error: e, stackTrace: stack);
} catch (e, stackTrace) {
debugPrint('loadImageAsset error: $assetPath: $e');
debugPrintStack(stackTrace: stackTrace);
return ImageLoadResult(error: e, stackTrace: stackTrace);
}
}