generateHighQualityImage function

Future<Uint8List?> generateHighQualityImage(
  1. Image image, {
  2. BuildContext? context,
  3. ImageGeneratioConfigs configs = const ImageGeneratioConfigs(outputFormat: OutputFormat.png, maxOutputSize: Size.infinite, processorConfigs: ProcessorConfigs(processorMode: ProcessorMode.minimum)),
})

Generates a high-quality image from the provided ui.Image.

  • image: The input ui.Image that needs to be processed.
  • configs: Optional configurations for the image editor, defaults to ProImageEditorConfigs.
  • context: The BuildContext allow to precache the image.

Returns a Future that resolves to a Uint8List containing the high-quality image data, or null if the image generation fails.

Example usage:

Uint8List? highQualityImage = await generateHighQualityImage(myImage);

Implementation

Future<Uint8List?> generateHighQualityImage(
  ui.Image image, {
  BuildContext? context,
  ImageGeneratioConfigs configs = const ImageGeneratioConfigs(
    outputFormat: OutputFormat.png,
    maxOutputSize: Size.infinite,
    processorConfigs: ProcessorConfigs(
      processorMode: ProcessorMode.minimum,
    ),
  ),
}) async {
  var recorder = ContentRecorderController(
    configs: ProImageEditorConfigs(
      imageGenerationConfigs: configs.copyWith(
        processorConfigs: configs.processorConfigs.copyWith(
          processorMode: ProcessorMode.minimum,
        ),
      ),
    ),
  );

  var bytes = await recorder.chooseCaptureMode(
    image: image,
    id: generateUniqueId(),
  );
  await recorder.destroy();

  if (context != null && context.mounted && bytes != null) {
    await precacheImage(MemoryImage(bytes), context);
  }

  return bytes;
}