repaintBoundaryToImage function

Future<Image?> repaintBoundaryToImage(
  1. RenderRepaintBoundary renderer
)

Implementation

Future<img.Image?> repaintBoundaryToImage(
  RenderRepaintBoundary renderer,
) async {
  try {
    final rawImage = await renderer.toImage(pixelRatio: 1);
    final byteData =
        await rawImage.toByteData(format: ui.ImageByteFormat.rawUnmodified);
    final pngBytes = byteData!.buffer;

    return img.Image.fromBytes(
      width: rawImage.width,
      height: rawImage.height,
      bytes: pngBytes,
      order: img.ChannelOrder.rgba
    );

  } catch (err) {
    return null;
  }
}