removeBackground method

  1. @override
Future<CutoutResult> removeBackground(
  1. String imagePath, {
  2. required CutoutOptions options,
})
override

Removes the background from an image at the given path.

Implementation

@override
Future<CutoutResult> removeBackground(
  String imagePath, {
  required CutoutOptions options,
}) async {
  try {
    final result = await methodChannel.invokeMethod<Object>(
      'removeBackground',
      {'imagePath': imagePath, 'options': options.toMap()},
    );

    return switch (result) {
      String path => CutoutFileSuccess(path),
      Uint8List bytes => CutoutBytesSuccess(bytes),
      _ => const CutoutFailure(
        CutoutErrorCode.processingFailed,
        'No result returned from native code',
      ),
    };
  } on PlatformException catch (e) {
    final code = _parseErrorCode(e.code);
    return CutoutFailure(code, e.message ?? 'Unknown error');
  }
}