captureEditorImage method

Future<Uint8List> captureEditorImage()

Captures the final editor image.

This method generates the final image of the editor content, taking into account the pixel ratio for high-resolution images. If generateOnlyImageBounds is set in imageGenerationConfigs, it uses the base pixel ratio; otherwise, it uses the maximum of the base pixel ratio and the device's pixel ratio.

Returns a Uint8List representing the final image.

Returns an empty Uint8List if the screenshot capture fails.

Implementation

Future<Uint8List> captureEditorImage() async {
  if (isSubEditorOpen) {
    Navigator.pop(context);
    if (!_pageOpenCompleter.isCompleted) await _pageOpenCompleter.future;
    if (!mounted) return Uint8List.fromList([]);
  }

  if (_imageInfos == null) await decodeImage();

  if (!mounted) return Uint8List.fromList([]);

  return await _controllers.screenshot.captureFinalScreenshot(
        imageInfos: _imageInfos!,
        backgroundScreenshot:
            stateManager.position > 0 ? stateManager.activeScreenshot : null,
        originalImageBytes: stateManager.position > 0
            ? null
            : await editorImage.safeByteArray(context),
      ) ??
      Uint8List.fromList([]);
}