captureImage method

void captureImage({
  1. required ImageInfos imageInfos,
  2. required List<ThreadCaptureState> screenshots,
  3. Size? targetSize,
  4. Widget? widget,
})

Capture an image of the current editor state in an isolate.

This method captures the current state of the image editor as a screenshot. It sets all previously unprocessed screenshots to broken before capturing a new one.

  • screenshotCtrl: The controller to capture the screenshot.
  • configs: Configuration for the image editor.
  • pixelRatio: The pixel ratio to use for capturing the screenshot.

Implementation

void captureImage({
  required ImageInfos imageInfos,
  required List<ThreadCaptureState> screenshots,
  Size? targetSize,
  Widget? widget,
}) async {
  if (!_configs.imageGenerationConfigs.generateImageInBackground ||
      !_configs.imageGenerationConfigs.generateInsideSeparateThread) {
    return;
  }

  /// Set every screenshot to broken which didn't read the ui image before
  /// changes happen.
  screenshots.where((el) => !el.readedRenderedImage).forEach((screenshot) {
    screenshot.broken = true;
  });
  ThreadCaptureState isolateCaptureState = ThreadCaptureState();
  screenshots.add(isolateCaptureState);
  Uint8List? bytes = widget == null
      ? await _capture(
          id: isolateCaptureState.id,
          imageInfos: imageInfos,
          stateHistroyScreenshot: true,
          onImageCaptured: (img) {
            isolateCaptureState.readedRenderedImage = true;
          },
        )
      : await captureFromWidget(
          widget,
          id: isolateCaptureState.id,
          imageInfos: imageInfos,
          targetSize: targetSize,
          stateHistroyScreenshot: true,
          onImageCaptured: (img) {
            isolateCaptureState.readedRenderedImage = true;
          },
        );
  isolateCaptureState.completer.complete(bytes ?? Uint8List.fromList([]));
  if (bytes == null) {
    isolateCaptureState.broken = true;
  }
}