crop method
Performs the actual cropping by calling the corresponding NativeImageCropper method. You can additionally set the ImageFormat for compression, defaults to ImageFormat.jpg.
Implementation
Future<Uint8List> crop({ImageFormat format = ImageFormat.jpg}) {
if ((cropRect, imageRect, imageSize, bytes)
case (
final Rect cropRect,
final Rect imageRect,
final Size imageSize,
final Uint8List bytes,
)) {
final x = (cropRect.left / imageRect.width * imageSize.width).toInt();
final y = (cropRect.top / imageRect.height * imageSize.height).toInt();
final width = cropSize.width.toInt();
final height = cropSize.height.toInt();
return switch (modeNotifier.value) {
CropMode.oval => NativeImageCropper.cropOval(
bytes: bytes,
x: x,
y: y,
width: width,
height: height,
format: format,
),
CropMode.rect => NativeImageCropper.cropRect(
bytes: bytes,
x: x,
y: y,
width: width,
height: height,
format: format,
),
};
}
throw const NativeImageCropperException(
'NullPointerException',
'Bytes, crop rect, image rect or image size are not initialized!',
);
}