cropRect method

  1. @override
Future<Uint8List> cropRect({
  1. required Uint8List bytes,
  2. required int x,
  3. required int y,
  4. required int width,
  5. required int height,
  6. ImageFormat format = ImageFormat.jpg,
})

Completes with an Uint8List of the cropped bytes in a rectangle shape.

Implementation

@override
Future<Uint8List> cropRect({
  required Uint8List bytes,
  required int x,
  required int y,
  required int width,
  required int height,
  ImageFormat format = ImageFormat.jpg,
}) async {
  final arguments = {
    'bytes': bytes,
    'x': x,
    'y': y,
    'width': width,
    'height': height,
    'imageFormat': format.name,
  };
  try {
    final croppedImage =
        await _methodChannel.invokeMethod<Uint8List>('cropRect', arguments);
    if (croppedImage == null) {
      throw const NativeImageCropperException(
        'NullPointerException',
        'Method channel cropRect() returns null!',
      );
    }
    return croppedImage;
  } on PlatformException catch (e) {
    throw NativeImageCropperException(e.code, e.message);
  }
}