cropImageToCenterBox static method

Future<Uint8List?> cropImageToCenterBox(
  1. Uint8List imageBytes,
  2. Rect calculatedRect
)

Implementation

static Future<Uint8List?> cropImageToCenterBox(
    Uint8List imageBytes, Rect calculatedRect) async {
  final originalImage = img.decodeImage(imageBytes);
  if (originalImage == null) return null;

  final cropX = calculatedRect.left.toInt();
  final cropY = calculatedRect.top.toInt();
  final cropWidth = calculatedRect.width.toInt();
  final cropHeight = calculatedRect.height.toInt();

  final cropped = img.copyCrop(
    originalImage,
    x: cropX,
    y: cropY,
    width: cropWidth,
    height: cropHeight,
  );

  return Uint8List.fromList(img.encodeJpg(cropped));
}