cropImage function

Future<Uint8List?> cropImage({
  1. required Uint8List rawImage,
  2. required EditActionDetails editAction,
  3. required Rect cropRect,
  4. required int imageWidth,
  5. required int imageHeight,
  6. required ExtendedImage extendedImage,
  7. required ImageProvider<Object> imageProvider,
  8. required bool isExtendedResizeImage,
})

Crop an image with various editing options and return it as a Uint8List.

This function allows you to crop an image using the specified editing options and return the result as a Uint8List.

Parameters:

  • rawImage: A Uint8List representing the raw image data.
  • editAction: An EditActionDetails object specifying editing actions like cropping, flipping, and rotating.
  • cropRect: A Rect representing the crop area.
  • imageWidth: The width of the original image.
  • imageHeight: The height of the original image.
  • extendedImage: An ExtendedImage widget for display.
  • imageProvider: An ImageProvider for the image.
  • isExtendedResizeImage: A boolean indicating whether the image is an ExtendedResizeImage.

Returns: A Future that resolves to a Uint8List containing the cropped image data.

Example Usage:

final Uint8List croppedImage = await cropImage(
  rawImage: imageBytes,
  editAction: editDetails,
  cropRect: cropRect,
  imageWidth: imageWidth,
  imageHeight: imageHeight,
  extendedImage: extendedImage,
  imageProvider: imageProvider,
  isExtendedResizeImage: isResizeImage,
);

Implementation

Future<Uint8List?> cropImage({
  required Uint8List rawImage,
  required EditActionDetails editAction,
  required Rect cropRect,
  required int imageWidth,
  required int imageHeight,
  required ExtendedImage extendedImage,
  required ImageProvider imageProvider,
  required bool isExtendedResizeImage,
}) {
  return isDesktop || isWebMobile
      ? cropImageDataWithDartLibrary(
          rawImage: rawImage,
          editAction: editAction,
          cropRect: cropRect,
          imageWidth: imageWidth,
          imageHeight: imageHeight,
          extendedImage: extendedImage,
          imageProvider: imageProvider,
        )
      : cropImageDataWithNativeLibrary(
          rawImage: rawImage,
          editAction: editAction,
          cropRect: cropRect,
          imageWidth: imageWidth,
          imageHeight: imageHeight,
          isExtendedResizeImage: isExtendedResizeImage,
        );
}