loadImage static method
Loads an image from local assets.
The path
argument is the path to the image file to be loaded. The
optional targetWidth
and targetHeight
arguments can be used to specify
the maximum width and height of the loaded image.
Implementation
static Future<ui.Image> loadImage(
String path, {
int? targetWidth,
int? targetHeight,
}) async {
final data = await rootBundle.load(path);
final bytes = Uint8List.view(data.buffer);
final codec = await ui.instantiateImageCodec(
bytes,
allowUpscaling: false,
targetWidth: targetWidth,
targetHeight: targetHeight,
);
return (await codec.getNextFrame()).image;
}