toImage method Null safety
Creates a raster image representation of the current state of the scene. This is a slow operation that is performed on a background thread.
Callers must dispose the Image
when they are done with it. If the result
will be shared with other methods or classes, Image.clone should be used
and each handle created must be disposed.
Implementation
Future<Image> toImage(int width, int height) {
if (width <= 0 || height <= 0) {
throw Exception('Invalid image dimensions.');
}
return _futurize((_Callback<Image?> callback) => _toImage(width, height, (_Image? image) {
if (image == null) {
callback(null);
} else {
callback(Image._(image, image.width, image.height));
}
}),
);
}