renderImage method
Future<ByteData>
renderImage({
- double pixelRatio = 1.0,
- ImageByteFormat format = ui.ImageByteFormat.png,
Used to render the image to ByteData which can then be stored or reused for example in an Image.memory widget.
Use pixelRatio
to increase the resolution of the resulting image.
You can specify a different format
, by default this method
generates pngs.
Implementation
Future<ByteData> renderImage({
double pixelRatio = 1.0,
ui.ImageByteFormat format = ui.ImageByteFormat.png,
}) async {
final renderObject = repaintBoundaryKey.currentContext?.findRenderObject()
as RenderRepaintBoundary?;
if (renderObject == null) {
throw StateError(
"Tried to convert Scribble to Image, but no valid RenderObject was "
"found!",
);
}
final img = await renderObject.toImage(pixelRatio: pixelRatio);
return (await img.toByteData(format: format))!;
}