chooseCaptureMode method
Future<Uint8List?>
chooseCaptureMode({
- required Image image,
- required String id,
- OutputFormat? format,
Selects the appropriate capture mode based on the platform and configuration.
This function determines the capture mode based on the platform and
configuration settings specified in _configs
. If the configuration
allows, the image generation may be offloaded to a separate thread or
web worker for better performance. If an error occurs, it falls back
to the main thread.
Implementation
Future<Uint8List?> chooseCaptureMode({
required ui.Image image,
required String id,
OutputFormat? format,
}) async {
format ??= _configs.imageGenerationConfigs.outputFormat;
if (_configs.imageGenerationConfigs.generateInsideSeparateThread) {
try {
if (!kIsWeb) {
// Run in dart native the thread isolated.
return await _captureWithNativeIsolated(
image: image,
id: id,
format: format,
);
} else {
// Run in web worker
return await _captureWithWebWorker(
image: image,
id: id,
format: format,
);
}
} catch (e) {
// Fallback to the main thread.
debugPrint('Fallback to main thread: $e');
return await _captureWithMainThread(image: image);
}
} else {
return await _captureWithMainThread(image: image);
}
}